는 :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['cart'][$productId]['quantity'] += $productQuantity;
:
번호으로 session_start : 명시 적으로 배열 (들)을 초기화하여, 그것을 일으키는 오류를 수정,
또는 첫째, 당신은 통지를하지 않도록 의도 한대로이 작동하고 가정 할 수있다(); if (! isset ($ _ SESSION [ 'cart'])) { $ _SESSION [ 'cart'] = []; } –
저는 숫자 대 문자열 색인 알림에 의해 캐치가 되살아납니다. P –