Always false, never true

This loop I am using is always false, it never comes back true, ever when it is. I don’t know what the error is. Can someone help?


$confEmail = mysql_query(
    sprintf(
        "SELECT Email FROM sq_users WHERE Email = '%s'",
        mysql_real_escape_string($_POST['email'])
    )
);
if(0 !== mysql_num_rows($confEmail)){
     //e-mail Exisits
}
else{
//E-mail doesn't exist
}

I don’t see any loop here
But you should check values carefully.
and check query result first.

Don’t save on the operators.
Make your code readable and error proof:

$email = mysql_real_escape_string($_POST['email']);
$sql = "SELECT Email FROM sq_users WHERE Email = '$email'")
$res = mysql_query($sql);
if (!$res) trigger_error(mysql_error().' in '.$sql);
if(0 !== mysql_num_rows($res)){
     //e-mail Exisits
} else{
//E-mail doesn't exist
} 

if it won’t throw any error, check your database twice if it really contain exact string. Remember there can be non-printable characters

Agreed, in general, you always want to do:

mysql_query(“…”) or die("Query failed: " . mysql_error());

to error-proof your code.

dying is very bad practice and should be thrown off our scripts, because

  1. it expose sensitive information
  2. it make erraneous page look awful. Emergency exit must be properly arranged

Thanks for the help! Problem solved!.