Q:

Pregmatch not matching correctly in php

Having trouble understanding what's going on here. Comments within the code explain. Thanks in advance.  To make it easier to read some code bits are missing like the writing to the DB part. But the problem is isolated to these lines. 
if (filter_var($email, FILTER_VALIDATE_EMAIL) == TRUE and 
preg_match("/^[\w ]+$/", $address_one) == TRUE and 
preg_match("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})", $password) == TRUE) {
//When given a valid email/address/password the code successfully gets to this point and inserts into a DB

} else {
    //When it fails validation with an invalid email/password/address it drops in here
    //but then it doesn't change error code variable...
    $errorcode = "IHAVENOTCHANGED";
    if (filter_var($email, FILTER_VALIDATE_EMAIL) == FALSE) {
            $errcode = " email,";
    }
    if (preg_match("/^[\w ]+$/", $address_one) == FALSE) {
            $errcode = " address line 1,";
    }
    if (preg_match("((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{8,20})", $password) == FALSE) {
            $errcode = " password,";
    }
    writetolog("LoginCreation", "Login failed due to invalid input: " . $errorcode . " - user: " . $email);
    echo "Invalid data for $errorcode please try again -- ADDRESS=$address_one -- EMAIL=$email -- PASS=$password";

}

A:

You have two different variables $errorcode and $errcode, and are using the former in your writetolog() call. If you put these lines at the top of your code (and remove $errorcode = "IHAVENOTCHANGED";), PHP should complain about the use of an undefined variable:
error_reporting(-1);
ini_set('display_errors', true);

You also need to surround your regular expression patterns with delimiters - i.e. / characters, as mentioned by @elclanrs.

