-3

运行代码时总是出现此错误

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

这是我的数据库

表 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);
    }
4

3 回答 3

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);

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

于 2013-08-31T17:18:51.900 回答
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"]; 
于 2013-08-31T17:19:22.167 回答
0

改变这个

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

 $orderid =$_GET['id']; 
于 2013-08-31T17:22:43.787 回答