forumnz Posted December 8, 2007 Share Posted December 8, 2007 <?php $con = mysql_connect("localhost","aaa","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } $id = "127"; $query = "SELECT title FROM 'help' WHERE 'id'=$id"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['title']; } mysql_close($con); ?> Gets me: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /httpdocs/clients/page.php on line 59 How do I fix it? Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/ Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Change $result = mysql_query($query); to $result = mysql_query($query) OR die ("Error in query: $query. " . mysql_error()); and post the error Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409965 Share on other sites More sharing options...
phpQuestioner Posted December 8, 2007 Share Posted December 8, 2007 try this: <?php $con = mysql_connect("localhost","aaa","aaa"); if (!$con) { die('Could not connect: ' . mysql_error()); } $id="127"; $query = "SELECT title FROM help WHERE id='$id'"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo $row['title']; } mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409967 Share on other sites More sharing options...
forumnz Posted December 8, 2007 Author Share Posted December 8, 2007 That didn't work phpQuestioner. Thanks though. This is the error I got: Error in query: SELECT title FROM 'help' WHERE 'id'=127. 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 ''help' WHERE 'id'=127' at line 1 Thanks. Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409971 Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 put help in back ticks `help` Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409972 Share on other sites More sharing options...
forumnz Posted December 8, 2007 Author Share Posted December 8, 2007 Thanks - it works! ;D Sam. Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409979 Share on other sites More sharing options...
revraz Posted December 8, 2007 Share Posted December 8, 2007 Thats because it's a reserved word. Mark as solved if all is well Link to comment https://forums.phpfreaks.com/topic/80814-solved-small-select-problem/#findComment-409980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.