这是cart.php:
foreach($_SESSION['cart'] as $k) {
<form class ="align-left"name="form1" method="post" action="cartqty.php">
<tr>
<td><p><?php $k['products_title']; ?></p></td>
<td><input type="text" name="product_qty[]" value=""/></td>
<td><input type="hidden" name="product_code" value="<?php $k['products_id']; ?>"/> </td>
<td><?php echo number_format($k['price'],2); ?></td>
</tr>
<?php
<input type="submit" name="submit" value="update">
}
?>
</table>
</form>
这是cartqty.php:
session_start();
$product_code = $_POST["product_code"];
$product_qty = $_POST["product_qty"];
如何获取输入文本数量的选择值,以便我可以相应地更新会话值,我总是得到product_qty数组的最后一个值。 请求帮助!!
答案 0 :(得分:0)
你需要在foreach块中关闭form标签,如:
foreach($_SESSION['cart'] as $k) {
<form class ="align-left"name="form1" method="post" action="cartqty.php">
<tr>
<td><p><?php $k['products_title']; ?></p></td>
<td><input type="text" name="product_qty[]" value=""/></td>
<td><input type="hidden" name="product_code" value="<?php $k['products_id']; ?>"/> </td>
<td><?php echo number_format($k['price'],2); ?></td>
</tr>
<?php
<input type="submit" name="submit" value="update">
</form>
}
?>
</table>