mysql SELECT and mysql_num_rows issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manRay
Forum Commoner
Posts: 78
Joined: Mon Feb 09, 2009 1:57 pm

mysql SELECT and mysql_num_rows issue

Post 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
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: mysql SELECT and mysql_num_rows issue

Post 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.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: mysql SELECT and mysql_num_rows issue

Post 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) {

}
Post Reply