-5

I always receive this error:

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

Here is my code:

$extra2 = mysql_fetch_array(mysql_query("SELECT desc from apps where id='$appid'"));
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132
Covrigelll
  • 11
  • 1
  • 4
    Please, [don't use `mysql_*` functions in new code](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). *They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation)*. See the [red box](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide which. – Jay Blanchard Oct 01 '14 at 17:42
  • 4
    [688 results](http://stackoverflow.com/search?q=Warning%3A+mysql_fetch_array%28%29+expects+parameter+1+to+be+resource) – Mike B Oct 01 '14 at 17:42
  • 1
    Let's run through the list: code is using deprecated interface (check), code is subject to SQL Injection vulnerabilities (check), code is not checking return from query execution (check), column references in query are not qualified (check), no indication of any effort to research the error (check), no indication of any attempt to debug the problem (check), no actual question asked in the question (check). (Hmmm. Thanks for the status report?) – spencer7593 Oct 01 '14 at 17:54

1 Answers1

3

desc is a MySQL reserved word

Either rename it to something else, or wrap it in backticks:

("SELECT `desc` from apps ... 

Being:


As spencer7593 commented (thank you) and I quote:

  • or, qualify the column reference: SELECT apps.desc FROM apps

I.e.:

("SELECT apps.desc FROM apps ... 
Community
  • 1
  • 1
Funk Forty Niner
  • 74,372
  • 15
  • 66
  • 132