【问题标题】:The If condition fails and goes to elseIf 条件失败并转到 else
【发布时间】:2017-05-05 14:57:15
【问题描述】:

$insertorderitems 中的 if 条件不满足,并且标头位置转到 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 必须是整数..
  • 什么问题?
  • 如果你连接它们,你不需要在查询之间用分号 (;) 分隔吗?
  • @arkascha 它在那里
  • @Naren 数据保存了吗?

标签: php mysql


【解决方案1】:

将您的查询更改为

 $sql .= "INSERT INTO order_items (order_id, product_id, quantity) VALUES (".$orderID.", ".$item['id'].", ".$item['qty'].");";

order_id 、product_id 和数量字段是整数

【讨论】:

    猜你喜欢
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 2016-05-15
    • 1970-01-01
    • 2011-11-06
    • 2020-09-15
    相关资源
    最近更新 更多