This is a note on an error that I have gotten several times when writing php scripts with mySQL.
The error is:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
The offending code snippet essentially looks like this:
$result = mysql_query(“$query_STRING” );
if (mysql_num_rows($result) > 0)
{which then continues on…
Note that $query_STRING is a string variable that contains the mySQL query.
The problem with this error message is that it is typically due to a problem in the query itself, and there can be many causes. To catch the cause, change the line that performs the query to:
$result = mysql_query(“$query_STRING” ) or die(mysql_error());
The statement die(mysql_error()) will catch the true error and with luck give you a more meaningful error message.
Posted under Programming, Software
This post was written by drknuth on January 31, 2009





Here’s a favorite code chunk of mine. It hides errors from your anonymous visitors, while allowing the developer to see the error based on the developer’s IP address (which goes where AA.BB.CC.DD is).
Or, if you like one-liners:
Huh. Doesn’t seem to like the php code enclosures. Here’s the same thing without them:
Here’s a favorite code chunk of mine. It hides errors from your anonymous visitors, while allowing the developer to see the error based on the developer’s IP address (which goes where AA.BB.CC.DD is).
if($_SERVER['REMOTE_ADDR']==”AA.BB.CC.DD”)
ini_set(‘display_errors’,'On’);
else
ini_set(‘display_errors’,'Off’);
Or, if you like one-liners:
ini_set(‘display_errors’,($_SERVER['REMOTE_ADDR']==”AA.BB.CC.DD”)? ‘On’:'Off’);