我一直在向结帐处发布一个很好的表单,但我需要我的表单来发布多个重复的字段。
我的数组现在显示
Array
(
[0] => Array
(
[id] => 65983c1c16d925e9a8cc4c4b3bdda1f5
[item] => Array
(
[1] => Brent New Product
[2] => Crazy Product
)
[unitprice] => Array
(
[1] => 100
[2] => 125
)
[quantity] => Array
(
[1] => 1
[2] => 1
)
)
)
但它需要显示为
Array
(
[0] => Array
(
[id] => 65983c1c16d925e9a8cc4c4b3bdda1f5
(
[product] => Brent New Product
[unitprice] => 100
[quantity] => 1
)
[id] => 4326526662262
(
[product] => Brent New Product2
[unitprice] => 140
[quantity] => 5
)
)
)
当我的表单从这个页面发布时,它会转到这个收集所有值的 php 脚本。
session_start();
$price = $_POST['price'];
$id = $_POST['id'];
$item = $_POST['item'];
$quantity = $_POST['quantity'];
echo '<h1>Add to cart</h1>';
echo "<p>Thank you for wanting a <strong>$item</strong>!</p>";
//We define an associative array with the details of our new item
$cart_row = array(
'id' => md5(rand()),
'item' => $item,
'unitprice' => $price,
'quantity' => $quantity
);
然后在购物车页面上,我希望显示购物车中的物品,但我没有得到任何填充框,它以前使用单个数组工作。
session_start();
foreach($_SESSION['cart'] as $item) { ?>
<tr>
<td><?php echo $item['item']; ?></td>
<td><?php echo $item['unitprice'];?></td>
<td><?php echo $item['quantity']; ?></td>
<td></td>
<td><form id="id" name="id" method="post" action="cart.php?remove=<?php echo $item["id"] ?>">
<input name="id" type="hidden" id="id" value="<? echo $item["id"]; ; ?>" />
<input name="Submit" type="submit" class="formbox" value="remove" />
</form></td>
</tr>
<?php } ?>