Jump to content

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


$php_mysql$

Recommended Posts

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{
}

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

 

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)){

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.
}

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.