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

Link to comment
Share on other sites

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
Share on other sites

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