i have prepared simple signup form in that i have used this line to check if the email already there in database or not if(mysql_query("SELECT email FROM $tbl_name1 WHERE email = '$a'")) { echo "email taken"; } PHP: ------------------------------- But not worked.. ------------------------------- but it worked if i give.. ------------------------------- if(mysql_num_rows(mysql_query("SELECT email FROM $tbl_name1 WHERE email = '$a'"))) { echo "email taken"; } PHP: What is the difference....! why first one is wrong........!
Short story: the first one is wrong because you are always passing a valid query string to mysql_query. Even if no results are found its still a valid use of mysql_query. Now, when turn around and pass that response from mysql_query to mysql_num_rows you have a different scenario. If results are found, then that is valid data you are passing on to mysql_num_rows, if no results are found then that is invalid data you are passing to mysql_num_rows and it responds as such.