message. Before checking the username and password against the database, we can check to see if the error message is blank: if ($errorMessage = = "") { } If it's blank, then everything is ok. In which case the rest of the code is executed. If it's not OK, then the user will see the text of the error message displayed. Inside of the if statement for the error message check, we just set up the database code like we did before: The code attempts to select all the records from the table where a match with the username is found. (L1 is the name of the username field in the table.) If any records are returned, then the variable called $num_rows will be greater than zero. We check the value of $num_rows in an if ... else statement. If the username has already been taken, then we can add something to the error message variable. (But there are security considerations to bear in mind here. Do you really want to tell a malicious user that a username has already been taken? If it's for a forum, then it's ok: the malicious user can simply read usernames from forum posts. But in that case, perhaps we shouldn't be using a username to log people in?) If the value in the variable $num_rows is still zero, then we can go ahead and add the user to the database: $SQL = " INSERT INTO login (L1, L2) VALUES ($uname, $pword)"; $result =