Moez Posted October 17, 2014 Share Posted October 17, 2014 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]" ; } } Link to comment https://forums.phpfreaks.com/topic/291896-mysql_fetch_row-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
Ch0cu3r Posted October 17, 2014 Share Posted October 17, 2014 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 https://forums.phpfreaks.com/topic/291896-mysql_fetch_row-expects-parameter-1-to-be-resource-boolean-given/#findComment-1494029 Share on other sites More sharing options...
ginerjm Posted October 17, 2014 Share Posted October 17, 2014 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 Link to comment https://forums.phpfreaks.com/topic/291896-mysql_fetch_row-expects-parameter-1-to-be-resource-boolean-given/#findComment-1494031 Share on other sites More sharing options...
mac_gyver Posted October 17, 2014 Share Posted October 17, 2014 given that you are using mysqli statements in your previous threads, i'm guessing the mysql_query() is failing because you should be using msyqli_query() Link to comment https://forums.phpfreaks.com/topic/291896-mysql_fetch_row-expects-parameter-1-to-be-resource-boolean-given/#findComment-1494035 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.