Jump to content

What is wrong with my script?


noisyscanner

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.