更新购物车.我想发送以前的数量和新数量


updating a cart.i want to send the previous quantity and the new quantity

我想使用 javascript 函数在 URL 中发送新数量、以前的数量和产品 ID。这是更新.php page.qty 是之前的数量,qty1 是要添加到此数量的新数量。

<?php
session_start();
include('custdb1.php');
$qty = $_GET['qty'];
$id = isset($_GET['id']) ? $_GET['id'] : '';
if (isset($_GET['id'])) {
    $id = $_REQUEST["id"];
    $qty = $_REQUEST["qty"];
    $_SESSION['cart'][$id] = array('id' => $id, 'qty' => $qty);
    echo "Quantity:" . $qty . '<br>';
    echo "Id:" . $id . '<br>';
    $sql = "SELECT `pro_img` FROM `product` WHERE `pro_id`=" . $id;
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        while ($row = $result->fetch_assoc()) {
            echo "<img src='upload/" . $row['pro_img'] . "'/>";
            echo "<br>";
            echo "Quantity: <input type='text' name='qty1' id='qty1" . $row["pro_id"] . "' value=''>";
            echo "<button onclick='up(" . $qty . "," . $id . ")'>update cart</button>";
        }
        //echo '<h4 align="center">  click here to <a href="update1.php?id='.$id.'&qty1='.$qty1.'&qty='.$qty.'">update cart</a> </h4>';
        // echo "<button onclick='up(".$qty.",".$id.")'>update cart</button>" ;
    }
}
//echo '<h4 align="center">  click here to <a href="update1.php?id='.$id.'&qty='.$qty1.'&qty='.$qty.'">update cart</a> </h4>';
?>
<script>
    function up(qty, id)
    {
        var qty1 = document.getElementById('qty1' + id).value;
        window.location = "update1.php?id=" + id + "&qty=" + qty + "qty1=" + qty1;
    }
</script>

您的代码对我来说似乎很好,但是当您尝试重定向它时会出现错误。绑定qty1时缺少&

你的代码应该是

window.location ="update1.php?id="+id+"&qty="+qty+"&qty1="+qty1;
return false; // use return false always when redirecting your page.