當表單提交以下錯誤:PHP公告:未定義的偏移和索引
PHP Notice: Undefined offset: 1 in E:\php\learning2\increase.php on line 10
PHP Notice: Undefined index: quantity in E:\php\learning2\increase.php on line 10
形式:
<form action="increase.php" method="post">
<input type="hidden" name="productId" value="1">
<input type="number" name="productQuantity" value="1">
<input type="submit" name="submit" value="Add to basket">
</form>
increase.php
session_start();
if (isset($_POST['submit'])) {
$productId = $_REQUEST['productId'];
$productQuantity = $_REQUEST['productQuantity'];
$_SESSION['cart'][$productId]['quantity'] += $productQuantity;
header('Location: http://localhost:8000/');
}
怎樣纔可以解決?
號在session_start (); if(!isset($ _ SESSION ['cart'])){ $ _SESSION ['cart'] = []; } –
我是一個被數字與字符串索引注意到的混淆:P –