...

View Full Version : Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource



Xaqa
10-26-2011, 01:26 AM
WRONG SECTION. DELETE PLEASE.






I have this code:


$number1 = "1";
$number2 = "1";
$seven = rand($number2, $number1);
$con = mysql_connect("my host","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM images WHERE $seven = $id");

while($result = mysql_fetch_array($result))
{
$title = $result['Title'];

echo $title;

}

Got this error on page: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /hermes/bosweb/web258/b2582/ipg.crowngaming/pictures.php on line 240

Here's line 240:


while($result = mysql_fetch_array($result))

Old Pedant
10-26-2011, 03:23 AM
This is almost surely wrong:


$result = mysql_query("SELECT * FROM images WHERE $seven = $id");

$seven and $id are *BOTH* PHP variables. Or, rather, they should be.

If $seven is not initialized, then your query becomes


SELECT * FROM images WHERE = 777

(or something like that). So you have a SQL error, and so you are *NOT* getting a valid $result.

You should do:


$result = mysql_query("SELECT * FROM images WHERE $seven = $id")
or die("<hr>error in SQL query: " . mysql_error() . "<hr>");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum