如何在其中添加数量?

时间:2018-08-23 03:51:45

标签: php sql

    <?php
    $main_subtotal = 0;
    $main_shipping_charge = 0;

    // create a product_id_stack
    $product_id_stack = "";

    foreach ($carts as $key => $cart) {
        $cart_id = $cart['id'];
        $cart_product_id = $cart['product_id'];
        // add product_id to the product_id_stack
        $product_id_stack .= $cart_product_id.",";

        $product = $db->Fetch("*","product","id='$cart_product_id'");

        /*shipping charge formating*/
        if ($product['shipping'] == 0) {
            $shipping_text = "<span class='text-bold text-green'>FREE</span>";
            $shipping_price = 0;
        }else{

            $shipping_text = "".$product['shipping'];
            $shipping_price = $product['shipping'];
        }

        $subtotal = $product['sp'] + $shipping_price;
        echo "
        <td><img src='{$product['image']}' class='cart-image'></td>
        <td>{$product['name']}</td>
        <td>{$product['sp']}.00 php</td>
        <td>{$subtotal}.00 php</td>
        <td><button class='remove-from-cart btn btn-primary text-18' id='{$cart_id}'><i class='fa fa-trash-o'></i></button></td>


        <tr>";

        /*calculate all the shipping charge*/

        $main_shipping_charge = $main_shipping_charge + $shipping_price;
        /*calculate all the sp*/
        $main_subtotal = $main_subtotal + $product['sp'];
    }
?>

那是我购物车中的代码。

这是添加到购物车中的代码

    if (isset($_POST['product_id'])) {
        $product_id = ($_POST['product_id']);
        $result = array();
        /*check login status*/
        if (isset($_SESSION['id'])) { /*logged in user*/
            $user_id = $_SESSION['id'];
            $insert = $db->Insert("cart","'','$product_id','$user_id','y',''");

            if ($insert) {
                $result['type'] = "success";
                $result['message'] = "Product has been added to the cart <a href='cart.php' class='text-bd-blue'>View Cart</a>";
            }else{
                $result['type'] = "error";
                $result['message'] = "Error try again.";
            }

        }else{ /* not logged in*/
            $result['type'] = "error";
            $result['message'] = "Please Login <a href='login.php' class='text-bd-blue'>Login</a>";
        }

        echo json_encode($result);
    }
?>

请帮我用这些代码先生/妈妈。我也在线观看视频,但是代码很复杂。我不知道如何在数据库中插入数量

请帮助我,我不知道该怎么做,我将在2个月内在这里上市。

0 个答案:

没有答案