0

I've downloaded a code from a website to make a comment section. The comment form shows up but the following error is given:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

What's the problem here? I tried several things but I really can't solve it myself, please help. This is the code:

// Error reporting:
error_reporting(E_ALL^E_NOTICE);

include "connect.php";
include "comment.class.php";

$comments = array();
$result = mysql_query("SELECT * FROM comments ORDER BY id ASC");

while($row = mysql_fetch_assoc($result))
{
    $comments[] = new Comment($row);
}
bemyhero
  • 63
  • 5

1 Answers1

0

When you run an query using mysql_query() function the returned value ($results) will be one of 2 values.

On success you will get your results as a "resource".

On failure you will get FALSE which is a "boolean".

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given

Your query returned FALSE which suggest there was a problem with your SQL query.

To debug this I would recommend checking your table/field names. You could also try quoting your table/field names with the ` character like this...

    $result = mysql_query("SELECT * FROM `comments` ORDER BY `id` ASC");
RCrowt
  • 906
  • 9
  • 19