I'm sure I have a simple syntax error in my code but I can't find it. The way this section of code should work is that the system checks if a userID exists, it is does or if the field is left empty, it creates an error. If it is ok it moves on to the next field which is userName and performs the same checks. Both of them report whether the corresponding value has been used before but neither of them report whether the field has been left empty.
if($userID != ""){
$sql = "SELECT * FROM tbl_access WHERE userID = '$userID'";
$result = mysql_query($sql) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows == 0){
$error = "User ID not found, please enter your user ID";
}
}
else if($userID == ""){
$error = "Please enter your User ID";
}
else if($username != ""){
$sql = "SELECT * FROM tbl_access WHERE userName = '$username'";
$result = mysql_query($sql) or die(mysql_error());
if(!empty($result)){
$error = "Username already in use, please select a different username";
}
}
else if($username == ""){
$error = "Please enter a username";
}
The script works fine when checking the user ID part but it completely ignores the username part. I'm sure it must be a simple syntax error on my part but I've been staring at the same part of code for hours now so any help will be gratefully recieved