Jump to content

mysql_fetch_row() expects parameter 1 to be resource, boolean given


Moez

Recommended Posts


 

the same query is running in other function 

 

 

function get_all_details()

{


global $connection ;

 

 $query = mysql_query("SELECT * FROM books LIMIT 5");

while( $detail= mysql_fetch_array($query)) 

{

  

  echo "$detail[isbn]<br> $detail[title]<br>$detail[price]<br>$detail[discription]" ;

}

  

}

This error usually indicates the query has failed. To see why the query has failed you can use mysql_error. Example

$query = mysql_query("SELECT * FROM books LIMIT 5");
if(!$query)
{
    trigger_error('MySQL Error: ' . mysql_error());
}

Also why are you defining $connection as global even though you don't use that variable in the function? If your function does require this variable you should pass it as an argument when you call the function.

PS - you should also use proper array syntax by quoting the indices.  Yes - it works now but sometimes it doesn't.  ($arr['index']) is the normal format and completely safe.

 

And since you have no other references in your query statement I can only guess that 'body' is not a valid tablename in the current db

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.