View Full Version : I get this often, dunno why...

03-02-2010, 09:10 PM

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/a9012858/public_html/scripts/getReview.php on line 14


include "connect.php";

//Connect to database
mysql_select_db($dbname, $con);

//Get data from database for current user
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM comments WHERE id=$id");
/*if (!result) {
echo "No reviews yet!";

while ($row = mysql_fetch_array($result)) {
//Variables to echo out data

//Display results
"<div class=\"comment\">
<div class=\"commentDiv\">Posted by $name</div>
<div class=\"message\">$message</div>
<div class=\"commentDiv\">Posted on $date</div>

I don't what is wrong with it....

03-02-2010, 09:14 PM
It means that the result resource you're trying to pull a row from isn't actually a result.

Change this:

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

To this:

$result = mysql_query("SELECT * FROM comments WHERE id=$id") or die(mysql_error());

and rerun your code. That will tell you if your query failed and why.

03-02-2010, 09:17 PM
Cheers :)

03-03-2010, 06:00 PM
It's also a good idea to wrap all of the values you use in single quotes for things like $id in your example
$result = mysql_query("SELECT * FROM comments WHERE id='$id'");
This means if your id accidentally has a string instead of a numeric value it's not going to throw an error about your query, it just won't return a result