0
if條件不$ insertorderitems滿足和頭部位置趨於checkout.php而不是ordersucess.php如果條件失敗,去別的
if($_REQUEST['action'] == 'placeOrder' && $cart->total_items() > 0 && !empty($_SESSION['sessCustomerID'])){
// insert order details into database
$insertOrder = $db->query("INSERT INTO orders (customer_id, total_price, created, modified) VALUES ('".$_SESSION['sessCustomerID']."', '".$cart->total()."', '".date("Y-m-d H:i:s")."', '".date("Y-m-d H:i:s")."')");
if($insertOrder){
$orderID = $db->insert_id;
$sql = '';
// get cart items
$cartItems = $cart->contents();
foreach($cartItems as $item){
$sql .= "INSERT INTO order_items (order_id, product_id, quantity) VALUES ('".$orderID."', '".$item['id']."', '".$item['qty']."');";
}
$insertOrderItems = $db->multi_query($sql);
if($insertOrderItems){
$cart->destroy();
header("Location: orderSuccess.php?id=$orderID");
}else{
header("Location: checkout.php");
}
那麼你的查詢肯定有問題。您的order_id和product_id必須是我認爲的整數。 – Demonyowh
是什麼問題? –
如果連接'em,你不需要在查詢之間使用分隔符(';')嗎? – arkascha