使用我的会话时MYSQL查询错误

时间:2013-03-12 18:20:15

标签: php mysql

我收到错误

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" 
}

1 个答案:

答案 0 :(得分:2)

你错过了sql中的FROM子句

它应该

     SELECT `order_id` FROM  your_table ORDER BY `order_id` DESC LIMIT 1
相关问题