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());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?