0

我收到错误

Query2 Error: 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

执行查询为我的购物车创建交易时。

function addNewTransaction($mem_id, $mem_tel, $mem_address, $mem_city, $mem_county, $mem_postcode, $mem_country, $item_id, $price, $each_item) {
// Insert into the transactions table
$query1 = mysql_query("INSERT INTO transactions (mem_id, OrderDate, Ship_Phone, Ship_Address, Ship_City, Ship_County, Ship_PostCode, Ship_Country) VALUES($member_data('mem_id'), NOW(), $member_data('mem_tel'), $member_data('mem_address'), $member_data('mem_city'), $member_data('mem_country'), $member_data('mem_postcode'), $member_data('mem_country'))");
if($query1) {
    // Get the highest ID in the transactions table. This should be the ID of the row we just inserted.
    $tempInfo = mysql_query("SELECT `order_id` ORDER BY `order_id` DESC LIMIT 1");
    $tempInfo = mysql_fetch_assoc($tempInfo);
    $orderId = $tempInfo['order_id'];

    // Insert into the transaction details table.
    $query2 = mysql_query("INSERT INTO `transactionDetails` (Order_ID, Product_ID, Price, Quantity) VALUES({$orderId}, {$item_id}, {$price}, {$each_item})");

    if($query2) {
        // Success.
    } else {
        // Error occurred.
        echo 'Query2 Error: ' . mysql_error();
    }
} else {
    // Error occurred.
    echo 'Query1 Error: ' . mysql_error();
}
}

我对我的会话感到困惑,当我执行 var_dump 时,我得到了这个

array(5) { 
 ["num_user"]=> string(1) "1" 
 ["mem_id"]=> string(2) "11" 
 ["cartTotal"]=> string(53) "Cart Total: £8.99 GBP" 
 ["cart_array"]=> array(1) { 
     [0]=> array(3) { 
        ["item_id"]=> string(1) "7"  
        ["quantity"]=> int(1) 
        ["price"]=> NULL 
     } 
  } 
 ["product_price"]=> string(4) "1.99" 
}
4

1 回答 1

2

你在你的 sql 中错过了FROM子句

它应该

     SELECT `order_id` FROM  your_table ORDER BY `order_id` DESC LIMIT 1
于 2013-03-12T18:25:49.090 回答