开发者

mysql fetch array error? [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I am getting Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\FBlike\like.php on line 104 in my script.. I'm not sure what that means and why it is happening.. help :)?

$like_id=mysql_real_escape_string($_GET['id']);

$sql=mysql_query("select * from likes WHERE id=$like_id DESC LIMIT 1");
while($row=mysql_fetch_array($sql))
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

   <met开发者_C百科a name="description" content="<?php print $row['like']; ?>"/>

  <meta name="keywords" content="<?php print $row['like']; ?>" />

    <meta property="og:description" content="Click to See More..." />

      <meta property="fb:app_id" content="" />



   <meta property="og:title" content="<?php print $row['like']; ?>"/>

   <meta property="og:type" content="activity"/>

     <meta property="og:url" content="http://www.fbquote.me/like.php?id=<?php print $row['id']; ?>" />

  <meta property="og:site_name" content="pDank" />
<title><?php print $row['like']; ?></title>

<?php } ?>


mysql_query() returns FALSE on error, ergo you have an error in your query.

Use mysql_error() to get the last error message.

For example

$result = mysql_query("select * from likes WHERE id=$like_id DESC LIMIT 1");
if (false === $result) {
    throw new Exception('MySQL error: ' . mysql_error());
}


You have an error in your SQL query.

Add the following code before mysql_fetch_array():

if (!$sql) {
    die(mysql_error());
}


That means your query failed for some reason (invalid syntax, column not found...) and returned FALSE.

To capture that, check if $sql (actually, you should name that variable $result or similar, that is much more common ($sql is typically used for query strings)) is FALSE and if so, print/log whatever the function mysql_error() returns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜