我想使用javascript函数在URL中发送新数量,先前数量和产品ID。 这是update.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>
答案 0 :(得分:0)
您的代码对我来说似乎不错,但是当您尝试重定向它时出错。绑定&
时,您将遗失qty1
。
您的代码应为
window.location ="update1.php?id="+id+"&qty="+qty+"&qty1="+qty1;
return false; // use return false always when redirecting your page.