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
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"));
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.