$_POST[$key] 在我的代码中没有返回值。var_dump($_POST) 给出了正确的结果。当我尝试回显 $_POST[$key] 时,它不会打印任何内容。我正在使用 mamp; 我阅读了关于类似问题的上一篇文章,但没有解决方案。这是我的代码...`
session_start();
if(isset($_POST["submit"])){
foreach($_SESSION["cart"] as $key => $qty){
if($_POST[$key] == '0'){
unset($_SESSION["cart"][$key]);
}
else
$_SESSION["cart"][$key] = $_POST[$key];
echo $_POST[$key];
}
var_dump($_POST);
}
$cart = $_SESSION["cart"];
?>
<table border="1" cellpadding="10">
<form action="<? echo $_SERVER["PHP_SELF"];?>" method="post">
<?
if($cart)
{
?>
<th>Item</th><th>Size</th><th>Quantity</th><th>Unit Price</th><th>Item Subtotal</th>
<?
$keys = array_keys($cart);
foreach($keys as $key)
{
echo $key;
$array = explode(".", $key);
$name = $array[0];
$size = $array[1];
$quantity = $cart["$key"];
echo $quantity;
$price = $xml->xpath("//item[@name='$name']/price[@size='$size']");
$unitPrice = (float) $price[0];
$itemSubtotal = $unitPrice * $quantity;
$total = $total + $itemSubtotal;
?>
<tr>
<td><? print($name); ?></td>
<td><? print($size); ?></td>
<? ?>
<td align="right"><input type = "text" name="<?print($key)?>" value="<? print($quantity); ?>" size="3"/></td>
<td align="right">$<? printf("%0.2f", $unitPrice); ?></td>
<td align="right">$<? printf("%0.2f", $itemSubtotal); ?></td>
</tr>
<?
}
?>
<tr><td colspan="5" align="right"><b>Total: $<? printf("%0.2f", $total); ?></b></td></tr>
<?
}
else
{
?>
Your cart is empty!
<? } ?>
<input type="submit" name="submit" value="update" />
</form>
</table>
<p><a href="checkout.php">Checkout</a></p>
`
谁能告诉我我的代码有什么问题?提前致谢。