$result1 = mysql_query("SELECT count(id) from account_details where username='$USERNAME' limit 0,1"); while($row = mysql_query($result1)) { if ($result1 == 0) { echo "DOESN'T EXIST"; } else { echo "DOES EXIST"; } }