Page 1 of 1

mysql SELECT and mysql_num_rows issue

Posted: Wed Jun 09, 2010 6:37 am
by manRay
I want to be able to check how many rows exists from

Code: Select all

$result = mysql_query("SELECT * FROM accounts WHERE email = $email");
if (mysql_num_rows($result) == 0) {

}
but I get the error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/s/l/i/********/html/***/register.php on line 17

Re: mysql SELECT and mysql_num_rows issue

Posted: Wed Jun 09, 2010 6:43 am
by markusn00b
If mysql_query() fails, it will return FALSE, not a MySQL Result Resource. You can grab MySQL's error message using the function mysql_error().

That said, I believe the error is because you're not putting quotes around $email.

Re: mysql SELECT and mysql_num_rows issue

Posted: Wed Jun 09, 2010 8:02 am
by internet-solution
I do something like this to debug errors

Code: Select all


$query="SELECT * FROM accounts WHERE email = '$email'";
$result  = mysql_query($query) or die (mysql_error()."- $query");
if (mysql_num_rows($result) == 0) {

}