2

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

I am getting the following error:

Warning: mysql_fetch_assoc() expects parameter 1 to be resource

My query seems fine, here is my code:

function products()
{
  $query = "SELECT id, quantity, price FROM dvd WHERE quantity > 0";
    if (!$query) 
    {
      echo "no product found";
      die(mysql_error());
    }
    else
    {
      while ($query_row = mysql_fetch_assoc($query)){
        echo "Test";
    }
  }
}

What does that error mean?

Community
  • 1
  • 1
exxcellent
  • 639
  • 4
  • 11
  • 18

4 Answers4

2

you forgot to execute the query:

mysql_query($query);
0

$query is just the text of the query. Change it to:

$query=mysql_query("SELECT id, quantity, price FROM dvd WHERE quantity > 0");
Brad
  • 152,561
  • 47
  • 332
  • 504
0

You forgot to call mysql_query() which actually executes it.

Replace the $query = ...; line with this:

$query = mysql_query("SELECT id, quantity, price FROM dvd WHERE quantity > 0");
ThiefMaster
  • 298,938
  • 77
  • 579
  • 623
0

You need to get a result from the query first...

$result = mysql_query($query);

... Then pass $result to mysql_fetch_assoc()

mysql_fetch_assoc($result);
DRiFTy
  • 11,159
  • 10
  • 63
  • 76