1
私はバスケットに追加して注文する簡単なカタログを作成しようとしていますが、問題があります:すべてがうまく動作し、ショッピングカートに必要な量の商品を追加していますしかし、私が別のものを追加したいのであれば、何も出てこない。それは単に1php特定の数量のバスケットに追加
フォームに数量を更新します。
<form action="buy.php" method="post">
<input type="hidden" name="productId" value="<?php echo $product['id']; ?>">
<?php if ($product['quantity'] === 0): ?>
<button type="submit" name="submit" disabled="true">Not available</button>
<?php else: ?>
<inputtype="number" name="productQuantity" value="1">
<button type="submit" name="submit">Add to cart</button>
<?php endif; ?>
</form>
buy.php
<?php
session_start();
if (isset($_POST['submit'])) {
$productId = $_POST['productId'];
$productQuantity = $_POST['productQuantity'];
$_SESSION['cart'][$productId] = [
'quantity' => $productQuantity
];
}
header('Location: http://localhost:8000/');
ありがとうございました!私は解決策を見つけました:$ _SESSION ['cart'] [$ productId] ['quantity'] + = $ productQuantity; –