Jump to content

[SOLVED] mysql_num_rows(): supplied argument is not a valid


lalabored

Recommended Posts

I get this error...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in readpm.php on line 22

 

With this code

 

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
$rscount = mysql_num_rows($rs);

 

Can someone tell me what's wrong?

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
$rscount = mysql_num_rows($rs);

 

The major problem I can see is that you're not checking to make sure that the mysql_query() function executed cleanly, when it doesn't $rs will be set to false.

 

You could try changing it to something like this:

 

$q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1";
$rs = mysql_query($q);
if (!$rs) { die("Could not query the database!"); }
$rscount = mysql_num_rows($rs);

 

The problem is that this is quite messy and I'm assuming that you haven't checked to make sure your mysql_connect and mysql_select_db functions have been executed cleanly.

 

I've written a short example on how to do the basics of this:

 

http://kritical.info/?p=8

 

I've written an example of how to do this a bit cleaner, although my example still uses die() if there is an error you could quite easily change this to your hearts content,

 

I hope this helps, cheers...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.