Clone512 Posted May 13, 2009 Share Posted May 13, 2009 For some reason I get this error from this script (yes, connect.php connects to the database and selects a database, without the where statement, it works fine, yes the field, to exists): <?php include("design/header.php"); require("connect.php"); $user = $_SESSION['user']; $query = mysql_query("SELECT * FROM inbox WHERE to='$user'"); $messages = mysql_num_rows($query); if($messages==0) { echo "You have no messages."; } else { echo "Test worked."; } include("design/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/ Share on other sites More sharing options...
kbfirebreather Posted May 13, 2009 Share Posted May 13, 2009 put "or die(mysql_error())" after your query, the query probably is failing Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-833618 Share on other sites More sharing options...
Clone512 Posted May 13, 2009 Author Share Posted May 13, 2009 Ok, did that here's the error I got: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'to='Testusr'' at line 1. But the problem is I don't get what's wrong. Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-833626 Share on other sites More sharing options...
Clone512 Posted May 14, 2009 Author Share Posted May 14, 2009 Bump Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-834023 Share on other sites More sharing options...
lonewolf217 Posted May 14, 2009 Share Posted May 14, 2009 try two things 1) set it up like this: <?php $sql = "SELECT * FROM inbox WHERE to='$user'"; echo $sql; $query = mysql_query($sql) or die(mysql_error()); and make sure the echo'd string is what you expect 2) it might fix it if you put brackets around your variable, like <?php $sql = "SELECT * FROM inbox WHERE to='{$user}'"; Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-834110 Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2009 Share Posted May 14, 2009 http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html to is a reserved work, rename your column to something else or put mysql specific back-ticks around it if you never expect to use your code on a different sql database. Link to comment https://forums.phpfreaks.com/topic/158032-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resource/#findComment-834115 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.