3raser Posted July 26, 2010 Share Posted July 26, 2010 Here is my query and execution code: $query = mysql_query("SELECT * FROM answers WHERE to='$to'"); while($row = mysql_fetch_assoc($query)) { $row['message'] = stripslashes($row['message']); echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>"; } Why do I keep getting this: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a9796960/public_html/qa.php on line 91 Everything is correct. Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/ Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 mysql_query is returning false. Change your query to: $query = mysql_query("SELECT * FROM answers WHERE to='$to'") or trigger_error(mysql_error()); To see what's wrong. Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091115 Share on other sites More sharing options...
Pikachu2000 Posted July 26, 2010 Share Posted July 26, 2010 My guess would be that $to has no value, and the query is failing because of that. Separate the query string from the execution, and echo with any errors it to see what's happening $query = "SELECT * FROM answers WHERE to='$to'"; $result = mysql_query($query) or die( 'Query string: ' . $query . '<br />Failed with error: ' . mysql_error() ); // change die to trigger_error for live sites while($row = mysql_fetch_assoc($result)) { $row['message'] = stripslashes($row['message']); echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>"; } Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091116 Share on other sites More sharing options...
3raser Posted July 26, 2010 Author Share Posted July 26, 2010 My guess would be that $to has no value, and the query is failing because of that. Separate the query string from the execution, and echo with any errors it to see what's happening $query = "SELECT * FROM answers WHERE to='$to'"; $result = mysql_query($query) or die( 'Query string: ' . $query . '<br />Failed with error: ' . mysql_error() ); // change die to trigger_error for live sites while($row = mysql_fetch_assoc($result)) { $row['message'] = stripslashes($row['message']); echo "Submitted on <b>". $row['date'] ."</b><br/><b><span style='color:green'>". $row['message'] ."</span></b><br/><br/>"; } Alright, I got this error: Query string: SELECT * FROM answers WHERE to='2' Failed with error: 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='2'' at line 1 Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091117 Share on other sites More sharing options...
Alex Posted July 26, 2010 Share Posted July 26, 2010 "to" is a reserved keyword, you need to use back-ticks. SELECT * FROM answers WHERE `to`='$to' Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091119 Share on other sites More sharing options...
3raser Posted July 26, 2010 Author Share Posted July 26, 2010 "to" is a reserved keyword, you need to use back-ticks. SELECT * FROM answers WHERE `to`='$to' Oh, thank you. Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091120 Share on other sites More sharing options...
Pikachu2000 Posted July 26, 2010 Share Posted July 26, 2010 See the MySQL reserved words manual page . . . Link to comment https://forums.phpfreaks.com/topic/208887-small-error-why-do-i-get-this-error-everything-is-correct-as-i-can-see/#findComment-1091121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.