Jump to content

Please tell me what's wrong?


Liquify

Recommended Posts

ERROR:
 
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/m4st3r/public_html/inbox.php on line 34

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/m4st3r/public_html/inbox.php on line 35
 
 
CODE:
 
$num = mysql_num_rows($allusers = mysql_query("SELECT * FROM PMs WHERE `status`='0' AND ReceiveID='$myU->ID' ORDER BY ID"));
$PMs = mysql_num_rows($allusers = mysql_query("SELECT * FROM PMs WHERE `status`='0' AND `LookMessage`='0' AND ReceiveID='$myU->ID' ORDER BY ID"));
 
 
PIC:
 
post-166853-0-40302000-1386977760_thumb.png

 

Link to comment
https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/
Share on other sites

try using this

$num = mysql_num_rows($allusers = mysql_query("SELECT * FROM PMs WHERE `status` = '0' AND ReceiveID ='".$myU->ID."' ORDER BY ID"));
$PMs = mysql_num_rows($allusers = mysql_query("SELECT * FROM PMs WHERE `status` = '0' AND LookMessage = '0' AND ReceiveID = '".$myU->ID."' ORDER BY ID"));

The query is failing, probably for the reason stated by AbraCadaver. Instead of chaining all of the function calls together, you should break it up and check for failures (especially in development).

 

// Instead of 
$num = mysql_num_rows($allusers = mysql_query("SELECT * FROM PMs WHERE `status`='0' AND ReceiveID='$myU->ID' ORDER BY ID"));

// Use this
$sql = "SELECT * FROM PMs WHERE `status`='0' AND ReceiveID='$myU->ID' ORDER BY ID";
$allusers = mysql_query($sql);
if (!$allusers) {
  // The query failed -- do something logical here
  trigger_error("Query Failed: $sql -- " . mysql_error(), E_USER_ERROR);
}
$num = mysql_num_rows($allusers);
Use this approach during development to have mySql and PHP tell you what is wrong. In production, you don't really want to just die like that - E_USER_ERROR kills the script - since the user will get a blank page (or only a partial page), and you don't want to show the error message to the user (security issue). You need to decide how to handle a fatal error so the user gets something meaningful. And yes, it is possible for a completely valid "working" query to fail after being moved to production -- The database server is down, the database server is overworked, the database itself becomes corrupt, etc.

 

Note: I left the error in the code above so the OP can see the error message and how it will help.

the original syntax is valid.

 

the query does need to ALWAYS be separated out and checked to see if it worked (and debugged if not to find out why it is failing - no database selected, problem with table/column names, problem with the connection...) before you can use any result that the query was expected to return.

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.