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]" ;

}

  

}

Edited by Moez
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.