noisyscanner Posted April 9, 2009 Share Posted April 9, 2009 My script: <?php $game_id = $_GET['id']; mysql_connect('localhost','username','pass'); mysql_select_db('database'); $result = mysql_query('select * from `games` where ID = $id'); while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { echo $row['game']; } ?> Is returning error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/brad291/public_html/games/play.php on line 6 What is wrong with my script? Link to comment https://forums.phpfreaks.com/topic/153360-what-is-wrong-with-my-script/ Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 You need to use double quotes in the query, not single or the $id variable won't interpolate. $result = mysql_query("select * from `games` where ID = $id"); Link to comment https://forums.phpfreaks.com/topic/153360-what-is-wrong-with-my-script/#findComment-805732 Share on other sites More sharing options...
AmandaF Posted April 9, 2009 Share Posted April 9, 2009 In addition to what Maq said, it looks like you're calling the same variable $game_id in one spot and $id in another. (Or are they supposed to be two separate variables?) Link to comment https://forums.phpfreaks.com/topic/153360-what-is-wrong-with-my-script/#findComment-805806 Share on other sites More sharing options...
Maq Posted April 9, 2009 Share Posted April 9, 2009 In addition to what Maq said, it looks like you're calling the same variable $game_id in one spot and $id in another. (Or are they supposed to be two separate variables?) Nice catch, yes, the OP probably wants: $result = mysql_query("select * from `games` where ID = '$game_id'"); Note: If field ID in your table is an integer then you don't need the single quotes. You should also cleanse your variables before putting them anywhere near your queries by calling mysql_real_escape_string() to prevent SQL Injections. Link to comment https://forums.phpfreaks.com/topic/153360-what-is-wrong-with-my-script/#findComment-805828 Share on other sites More sharing options...
noisyscanner Posted April 14, 2009 Author Share Posted April 14, 2009 Fixed it now! Thanks for helping! Link to comment https://forums.phpfreaks.com/topic/153360-what-is-wrong-with-my-script/#findComment-810037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.