为什么此表单不会更新会话中项目的值?在表单尝试允许用户编辑值之前,会话似乎跟踪值正常。这是我写的表格提交:
<?php
if(isset($_POST['submit'])){
foreach($_POST['quantity'] as $key => $val) {
if($val==0) {
unset($_SESSION['Cart'][$key]);
}else{
$_SESSION['Cart'][$key]['quantity']=$val;
}
}
}
?>
以下是表格:
<?php
$sql="SELECT * FROM products where Product_ID IN (";
foreach($_SESSION['Cart'] as $id => $value){
$sql.=$id.",";
}
$sql=substr($sql, 0, -1).") ORDER BY Category ASC";
$query=mysql_query($sql);
$totalquantity=0;
while($row=mysql_fetch_array($query)){
$subtotal=$_SESSION['Cart'][$row['Product_ID']['quantity']]['quantity'];
$totalquantity+=$subtotal;
?>
<tr>
<td><?php echo $row['Name'] ?></td>
<td><input = type="text" name="Quantity [<?php echo $row['Product_ID'] ?>]" size="5" value="<?php echo $_SESSION['Cart'][$row['Product_ID']['quantity']]['quantity'] ?>"/> </td>
</tr>
<?php
}
?>
当然,提交按钮只是
<button type="Submit" name="Submit">Update selection</button>
它看起来应该都能正常运行,但它不会更新。
答案 0 :(得分:0)
提交最有可能是“提交”。在输入字段或$ _POST [“提交”]中更改