Liquify Posted December 13, 2013 Share Posted December 13, 2013 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: Quote Link to comment https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/ Share on other sites More sharing options...
AbraCadaver Posted December 14, 2013 Share Posted December 14, 2013 (edited) $allusers = mysql_query("SELECT * FROM PMs WHERE `status`='0' AND ReceiveID='$myU->ID' ORDER BY ID"); if(!$allusers) { echo mysql_error(); } Just a guess but you'll probably need: ReceiveID='{$myU->ID}' Edited December 14, 2013 by AbraCadaver Quote Link to comment https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/#findComment-1462315 Share on other sites More sharing options...
PravinS Posted December 14, 2013 Share Posted December 14, 2013 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")); Quote Link to comment https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/#findComment-1462316 Share on other sites More sharing options...
DavidAM Posted December 14, 2013 Share Posted December 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/#findComment-1462337 Share on other sites More sharing options...
mac_gyver Posted December 14, 2013 Share Posted December 14, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284759-please-tell-me-whats-wrong/#findComment-1462342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.