download12749 2014-05-05 20:13
浏览 40
已采纳

PHP购物车错误:警告:mysql_num_rows()期望参数1是资源,布尔给定[重复]

I'm creating a shopping cart systems and I'm getting this error when trying to add the item to the cart.

<?php 
session_start();

require('inc/connect.php');

if(isset($_GET['action']) && $_GET['action']=="add") {

    $id=intval($_GET['id']);
    if(isset($_SESSION['cart'][$id])) {
        $_SESSION['cart'][$id]['quantity']++;
    }
    else {

        $sql_s ="SELECT * FROM product WHERE product_id = ['id']";
        $query_s=mysql_query($sql_s);
        if(mysql_num_rows($query_s) !=0) {
            $row_s=mysql_fetch_array($query_s);

            $_SESSION['cart'][$row_s['product_id']]==array(
                "quantity" => 1,
                "price" => $row_s['price']);
        }
        else {
            $message="This product id is invalid!";
        }
    }
}

?>

My error is saying line 16 which is:

$query_s=mysql_query($sql_s);
</div>
  • 写回答

1条回答 默认 最新

  • douyue3800 2014-05-05 20:17
    关注

    Change ['id'] to $id:

    $sql_s ="SELECT * FROM product WHERE product_id = $id";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度