Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.