警告:mysql_fetch_assoc()期望参数1是资源,布尔值在

时间:2013-08-31 17:12:15

标签: php mysql sql

当我运行我的代码

时,我总是会收到此错误
0:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\fyp\admin_vieworders_details.php on line 12
Query Failed!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

这是我的数据库

table order_detail {Order_Detail_ID(PK),Order_Quantity,Sub_Total}

表单{Order_ID,Order_Date,Order_Time,Delivery_Charge,Delivery_Name}

这是我的代码

$orderid =@$_GET["id"];  
$detail = "SELECT 
                order.*,
                order_detail.Order_Quantity,
                order_detail.Sub_Total
            FROM `order` AS a, `order_detail` AS b
            WHERE order_detail.Order_ID = `order`.Order_ID AND order_detail.Order_Detail_ID=$orderid";

$result = mysql_query($detail);
$row = mysql_fetch_assoc($result);

        if($result === FALSE)
    {
            die("Query Failed!".mysql_error().$result);
    }

3 个答案:

答案 0 :(得分:1)

在致电mysql_error()之前检查mysql_fetch_assoc()。您的查询失败,查询函数返回false

$result = mysql_query($detail);
if (!$result) {
    die("Error: ".mysql_error()); // Note: raw database errors are useless for users
                                  // better log the error an create a "nice" error page
}
$row = mysql_fetch_assoc($result);

或者这样可能会让你开始。

答案 1 :(得分:1)

您的查询中似乎有错误:

尝试:

$detail = "SELECT 
                a.*,
                b.Order_Quantity,
                b.Sub_Total
            FROM `order` AS a, `order_detail` AS b
            WHERE b.Order_Detail_ID = a.Order_ID AND
                  b.Order_Detail_ID=$orderid";

而不是

$detail = "SELECT 
                order.*,
                order_detail.Order_Quantity,
                order_detail.Sub_Total
            FROM `order` AS a, `order_detail` AS b
            WHERE order_detail.Order_ID = `order`.Order_ID AND
                   order_detail.Order_Detail_ID=$orderid";

还有......

$orderid =$_GET["orderid"]; 

而不是

$orderid =@$_GET["id"]; 

答案 2 :(得分:0)

更改此

 $orderid =@$_GET["id"]; 

 $orderid =$_GET['id'];