$php_mysql$ Posted August 14, 2011 Share Posted August 14, 2011 what is wrong in this code that i get this error? Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\pt\functions\functions.php on this line while($row = mysql_fetch_array($result)){ $sql="SELECT id, image FROM tbl WHERE time < '".$match_time."'"; echo $sql; $result = mysql_query($sql); if(!$result){ echo 'SELECT failed: '.mysql_error(); }else{ while($row = mysql_fetch_array($result)){ $id = $row['id']; if(!unlink($row['image'])){ echo "unlink ".$row['image']." failed"; }else{ } Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
phpSensei Posted August 14, 2011 Share Posted August 14, 2011 try this $sql="SELECT `id`, `image`,`time` FROM `tbl` WHERE `time` < '".$match_time."'"; echo $sql; $result = mysql_query($sql); if(!$result){ echo 'SELECT failed: '.mysql_error(); }else{ while($row = mysql_fetch_array($result)){ $id = $row['id']; if(!unlink($row['image'])){ echo "unlink ".$row['image']." failed"; }else{ } http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257013 Share on other sites More sharing options...
$php_mysql$ Posted August 14, 2011 Author Share Posted August 14, 2011 still getting the same error Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257014 Share on other sites More sharing options...
phpSensei Posted August 14, 2011 Share Posted August 14, 2011 Your queries seem to be fine. change this line $result = mysql_query($sql); to $result = mysql_query($sql) or die(mysql_error()); Give the exact error output. Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257015 Share on other sites More sharing options...
$php_mysql$ Posted August 14, 2011 Author Share Posted August 14, 2011 thats what im wondering i changed the line but no it will says Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\pt\functions\functions.php on line 440 which is while($row = mysql_fetch_array($result)){ Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257016 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 This is cause by simply passing the result of mysql_query to mysql_fetch_assoc without first checking it succeeded. The general syntax used for a select should be: if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // $result contains data } else { // no results found } } else { // query failed. } Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257017 Share on other sites More sharing options...
$php_mysql$ Posted August 14, 2011 Author Share Posted August 14, 2011 eh error_reporting(0) the savior :-D Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257042 Share on other sites More sharing options...
trq Posted August 14, 2011 Share Posted August 14, 2011 Or you could learn to write better code. Link to comment https://forums.phpfreaks.com/topic/244732-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1257044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.