dongpo5264 2012-02-28 12:33
浏览 133

“警告:mysql_fetch_array()期望参数1是资源,布尔给出”尝试创建php购物车时出错[重复]

Possible Duplicate:
PHP Error: mysql_fetch_array() expects parameter 1 to be resource, boolean given

This is the code I have in my product.php, every time I click on a product from the home page it comes up with the warning below:

if ( isset( $_GET['ID'] ) ) {
    $product_id = $_GET['ID'];
    $query = "SELECT Name, Genre, Price, Year, Picture FROM Products";
    $result = mysql_query( $query );

    while ( $row = mysql_fetch_array( $result, MYSQL_NUM ) ) {
        echo "<div><p>Name: $row[0]</p><p>Genre: $row[1]</p><p>Price: $row[2]</p><p>Year: $row[3]</p></div>";
    }
    echo "<div><a href=\"cart.php?action=add&product=$product_id\">add to basket</a></div>";
}

and I get the warning:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/cart/product.php on line 12

  • 写回答

2条回答 默认 最新

  • douao1854 2012-02-28 12:34
    关注

    Year is a mysql reserved word you have to escape it using backticks ``

    $query = "SELECT Name, Genre, Price, `Year`, Picture FROM Products";
    

    you must use some kind of mysql error checking like below one

    $result = mysql_query($query) or trigger_error(mysql_error());
    
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程