-4

Possible Duplicate:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

ERROR -> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

    $sql = "SELECT * FROM pictures WHERE filename=$filename";
//makes a query to the database using the question in variable sql.
$result = mysql_query($sql);

ERROR ->if(!($row = mysql_fetch_array($result)))
    {
     //code.......

I don't get it, what am I doing wrong, there is nothing wrong about the parameter...

Community
  • 1
  • 1
  • 1
    Is that what your code actually looks like? – Tyler Crompton Sep 11 '12 at 16:49
  • 1
    Not sure whether you already know this, but just in case you are wondering [How accepting an answer works](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235). If you already know this just ignore this comment :) – PeeHaa Sep 11 '12 at 16:52

2 Answers2

3

It means that there's something wrong with your query. At a guess, I'd suggest that you need to quote out your variable:

$sql = "SELECT * FROM pictures WHERE filename='$filename'";

HOWEVER

You should also look at not using mysql_* functions - they're being deprecated. If you switch to PDO or mysqli_, they not only help you produce more secure code, they also sort out the quoting of values for you.

ficuscr
  • 6,885
  • 2
  • 31
  • 50
andrewsi
  • 10,995
  • 132
  • 34
  • 49
  • Ok, thanks for the tip. But it does not solve the error – user1214054 Sep 11 '12 at 16:52
  • Can you trying echoing out the SQL you're generating, and running it directly in the database? – andrewsi Sep 11 '12 at 16:53
  • Ok, if I wanted to do this lines of code, your way with the not deprecated functions, how would you. Im doing a course with a book from -91. Maby that is why i am learning this crappy programming...please help me – user1214054 Sep 11 '12 at 16:57
  • The php website has a lot of information on PDO http://php.net/manual/en/intro.pdo.php and mysqli http://us3.php.net/manual/en/mysqli.quickstart.php – andrewsi Sep 11 '12 at 17:00
  • @user1214054 [Good PDO tutorial](http://goo.gl/vFWnC) – PeeHaa Sep 11 '12 at 17:01
2

The error message is pretty clear, the value returned from mysql_query is a boolean (FALSE) not a resource, which means your query failed.

You probably want something like:

$sql = "SELECT * FROM pictures WHERE filename='$filename'";
$result = mysql_query($sql);
if($result && $row = mysql_fetch_array($result)) { ... }