Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在这些中添加数量?_Php_Sql - Fatal编程技术网

Php 如何在这些中添加数量?

Php 如何在这些中添加数量?,php,sql,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_produc

这是我购物车中的代码

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

    <?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($\u POST['product\u id'])){
$product_id=($_POST['product_id']);
$result=array();
/*检查登录状态*/
如果(isset($_SESSION['id']){/*登录用户*/
$user\u id=$\u会话['id'];
$insert=$db->insert(“购物车”、“产品id”、“用户id”、“y”和“);
如果($插入){
$result['type']=“成功”;
$result['message']=“产品已添加到购物车”;
}否则{
$result['type']=“error”;
$result['message']=“错误,请重试。”;
}
}else{/*未登录*/
$result['type']=“error”;
$result['message']=“请登录”;
}
echo json_编码($result);
}
?>
先生/女士,请帮我输入这些代码。我也在网上看视频,但代码很复杂。我不知道如何在数据库中插入数量


请帮帮我,伙计们,我不知道怎么做,我两个月后就有货了。

欢迎光临。所以,我假设现在您只能保存到数据库?或者您想再添加一个插入列?您的问题很模糊。我可以看看你的
$db->Insert()
正文和你想插入的表结构吗?波比先生,我想为quantityif($Insert){/*获取最后一个插入的\u id*/$buy\u id=mysqli\u Insert\u id($mysqli);/*停用购物车表中的行*/$update=$db->Query(“更新
cart
SET
active
='n',buy_id='$buy_id',其中
user_id
='user_id'”;
    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);
    }
?>