Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.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/9/three.js/2.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_Html_Shopping Cart - Fatal编程技术网

Php 购物车:更新和删除购物车中的产品

Php 购物车:更新和删除购物车中的产品,php,html,shopping-cart,Php,Html,Shopping Cart,嘿,我想建立一个网上购物网站,但我被卡在购物车区 我试图在文本框中显示产品的数量,并对其进行更新,这似乎与我的代码不符,而且我无法从购物车中删除产品 im使用删除复选框、提交类型的更新按钮和文本框显示数量 下面是my cart.php页面的代码 <form action="" method="post" enctype="multipart/form-data"> <table align="center" width="700px" bgcolor="skyblue

嘿,我想建立一个网上购物网站,但我被卡在购物车区

我试图在文本框中显示产品的数量,并对其进行更新,这似乎与我的代码不符,而且我无法从购物车中删除产品

im使用删除复选框、提交类型的更新按钮和文本框显示数量

下面是my cart.php页面的代码

<form action="" method="post" enctype="multipart/form-data">

    <table align="center" width="700px" bgcolor="skyblue">

    <tr align="center">
        <th>Remove</th>
        <th>Products</th>
        <th>Quantity</th>
        <th>Total Price</th>
    </tr>

<?php 

$total = 0;

global $con;

$ip = getIp();

$select_price = "select * from cart where ip_addr = '$ip'";

$run_price = mysqli_query($con, $select_price);

while ($p_price = mysqli_fetch_array($run_price)) {

    $pro_id = $p_price['p_id'];
    $pro_qty = $p_price['qty'];

    $pro_price = "select * from products where product_id = '$pro_id'";

    $run_pro_price = mysqli_query($con, $pro_price);

    $select_qty = "select * from cart where p_id = '$pro_id'";

    $run_qty = mysqli_query($con, $select_qty);

    $row_qty = mysqli_fetch_array($run_qty);

    $qty = $row_qty['qty'];

    while ($pp_price = mysqli_fetch_array($run_pro_price)) {

        $product_price = array($pp_price['product_price']);
        $product_title = $pp_price['product_title'];
        $product_image = $pp_price['product_image'];

        $single_price = $pp_price['product_price'];

        $values = array_sum($product_price);

        $total += $values;

?>

    <tr align="center">
        <td><input type="checkbox" name="remove[]" value="<?php echo 
$pro_id; ?>"></td>
        <td><?php echo $product_title; ?><br>
        <img src="Admin_area/product_image/<?php echo $product_image; ?>" 
width="60px" height="60px">
        </td>
        <td><input type="text" name="qty" size="4px" value="<?php echo $qty; 
?>"></td>  // Calling the $qty variable which store the product quantity

        <?php

        if (isset($_POST['update_cart'])) {

            $qty = $_POST['qty'];
            $update_qty = "update cart set qty='$qty' where p_id = 
'$pro_id'";
            $run_qty = mysqli_query($con, $update_qty);

            $_SESSION['qty'] = $qty;

            $total = $total*$qty;

            echo "<script>window.open('cart.php','_self')</script>";

        }

        ?>

        <td>&#8360 <?php echo $single_price; ?></td> 
    </tr>

    <?php } } ?>

    <tr align="right">
        <td colspan="2" style="padding: 10px;"><b>Sub Total:</b></td>
        <td colspan="2" style="padding: 10px;">&#8360 <?php echo $total; ?>
</td>
    </tr>

    <tr align="center">
        <td colspan="2"><input type="submit" name="update_cart" 
value="Update Cart"></td>
        <td><button><a href="index.php" style="text-decoration: none; color: 
black;">Continue</a></button></td>
        <td><button><a href="checkout.php" style="text-decoration: none; 
color: black;">Checkout</a></button></td>
    </tr>


    </table>

    </form>

    <?php 

    function updatecart(){

    $ip = getIp();

    if (isset($_POST['update_cart'])) {

 // when update cart button clicked delete all product which are checked

        foreach ($_POST['remove'] as $remove_id) {

            $delete_product = "delete from cart where p_id = '$remove_id' 
AND ip_addr = '$ip'";

            $run_delete = mysqli_query($con,$delete_product);

            if ($run_delete) {

        echo "<script>alert('Inside Function');</script>";


                echo "<script>window.open('cart.php','_self')</script>";
            }

        }

    }

    elseif (isset($_POST['continue'])) {

        echo "<script>window.open('index.php','_self')</script>";

    }

}

echo @$update_cart = updatecart();

?>          

    </div>

去除
产品
量
总价

旁注:如果您正在使用mysqli构建新代码,请研究为任何插入了变量的查询使用准备好的语句(特别是如果该变量来自用户端数据)。旁注:如果您正在使用mysqli构建新代码,请研究为任何插入了变量的查询使用准备好的语句(特别是当该变量来自用户端数据时)。