Page 1 of 1

problem with mysql_num_rows

Posted: Thu Jan 17, 2008 3:11 pm
by smoky989
I'm having some issues trying to get a count with "mysql_num_rows". Here's my code and the errors I am getting. (I also tried using the count(*) function but had no luck. Thanks in advance for any help.

Code: Select all

//Connecting to the database
 
$db = mysql_connect("localhost", "user", "pass");
 
mysql_select_db ("jpobrien");
 
$result = mysql_query("select first_name_1 from Customers", $db);
$number = mysql_num_rows($result);
 
$customer_id = $number + 9000;
Here's the error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jpobrien/public_html/staff/customer_new_enter.php on line 56
There was a problem with the database server. Please try again later

Re: problem with mysql_num_rows

Posted: Thu Jan 17, 2008 3:17 pm
by Zoxive

Code: Select all

$db = mysql_connect("localhost", "user", "pass") or die("Mysql Error: <br>\n" . mysql_error());
#  
mysql_select_db ("jpobrien",$db);
#  
$result = mysql_query("select first_name_1 from Customers", $db) or die("Mysql Error: <br>\n" . mysql_error());
$number = mysql_num_rows($result);
#  
$customer_id = $number + 9000;
Most likely a mysql error...

Any reason you link the resource for the query, and not the database select?

Re: problem with mysql_num_rows

Posted: Thu Jan 17, 2008 3:19 pm
by Jade
It's probably a problem with your query. Adding mysql_error() as zoxive said above will help you figure out what's wrong. You could be trying to select a name that doesn't exist in the database.