mysql_fetch_array()参数问题

时间:2013-08-22 11:00:42

标签: php mysql

$uid = $_GET['id'];
echo $sql = "select * from notice where id=$uid";
echo $result = mysql_query($sql);
$row = mysql_fetch_array($result);
    echo $row['headline'];
    echo $row['description'];
    echo $row['image'];

正在制作

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\willammary\staff-admin\edit_notice.php on line 5

1 个答案:

答案 0 :(得分:0)

试试这个,

$uid = $_GET['id'];
echo $sql = "select * from notice where id=".$uid;
echo $result = mysql_query($sql);
if($result === FALSE) {
    die(mysql_error()); // error handling
}
$row = mysql_fetch_array($result);
echo $row['headline'];
echo $row['description'];
echo $row['image'];

<强>可替换地,

$uid = $_GET['id'];
echo $sql = "select * from notice where id=$uid";
echo $result = mysql_query($sql);
if($result) {
   $row = mysql_fetch_array($result);
   echo $row['headline'];
   echo $row['description'];
   echo $row['image'];
}

$uid = $_GET['id'];
echo $sql = "select * from notice where id=$uid";
echo $result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
echo $row['headline'];
echo $row['description'];
echo $row['image'];

PHP 5.5.0开始, mysql扩展deprecated 阅读http://www.php.net/manual/en/intro.mysql.php