1
javascript機能を使用して、URLに新しい数量、前の数量、製品IDを送信します。 これはupdate.php page.qtyは以前の数量であり、qty1はこれに追加される新しい数量です。cart.iを更新する前の数量と新しい数量を送信します
<?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>
すべきですか? – urfusion