1

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

I am connected with my database and there seems to be an error appearing on this line of code:

  while($br = mysql_fetch_assoc($brand))

and on my query I put this:

  $brand = mysql_query("Select * from genratb");

The error says

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\videoshop\index.php on line 166

The first command is actually my line 166.

Community
  • 1
  • 1
babymalady
  • 27
  • 1
  • Add your code .. and arrangement – Baba Oct 11 '12 at 00:51
  • 2
    put the code inside the `while` loop here,pls. – undone Oct 11 '12 at 00:55
  • Read http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12770072#12770072 – Jocelyn Oct 11 '12 at 01:00
  • 1
    We need to see the actual code in the correct order. Either your query failed because you aren't connected or the table genratb doesn't exist, or you are doing something like overwriting the variable `$brand` inside the while loop. We need code. – Michael Berkowski Oct 11 '12 at 01:00

3 Answers3

1

It looks like your query failed. The mysql_query call probably returned false, instead of the result resource.

$brand = mysql_query("Select * from genratb");

if (!$brand)
{
    //error, query failed
}

else
{
    while($br = mysql_fetch_assoc($brand))
    {
       //use row
    }
}
Geoff Montee
  • 2,587
  • 13
  • 14
0

If they query fails, then mysql_query() will return false. In that case, you need to look at mysql_error() to find out why the query failed.

staticsan
  • 29,935
  • 4
  • 60
  • 73
0

The PHP documentation states:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

Most likely your query is failing for some reason, and setting $brand to FALSE. Are you sure your database connection is working, and your table exists?

You can add after your query line:

if (FALSE===$brand) { die(mysql_error()); }

This should tell you what is going wrong.

craigmj
  • 4,827
  • 2
  • 18
  • 22