장바구니 프로젝트를 수행하려고합니다. 제품 목록의 항목에 대해 양식을 설정하는 방식에 따라 선택한 항목 만 장바구니에 표시되지만 대신 클릭 한 항목이 세 항목 모두 표시됩니다. 누군가 내가 바꿀 필요가있는 것을 말해 줄 수 있습니까?PHP 장바구니에서 선택하지 않은 항목 표시
제품이 나와 얻을 메인 페이지 :
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP Final Project</title>
</head>
<body>
<?php
$_SESSION['maxItems'] = 2;
?>
<form id="item01" method="post" action="cart.php">
<?php $_SESSION['cart'][0] = array('name'=>'item01','price'=>'$11'); ?>
<label>Item 01 for sale</label>
<input type="submit" value="Add to cart" name="item01">
</form>
<br>
<form id="item02" method="post" action="cart.php">
<?php $_SESSION['cart'][1] = array('name'=>'item02','price'=>'$22'); ?>
<label>Item 02 for sale</label>
<input type="submit" value="Add to cart" name="item02">
</form>
<br>
<form id="item03" method="post" action="cart.php">
<?php $_SESSION['cart'][2] = array('name'=>'item03','price'=>'$33'); ?>
<label>Item 03 for sale</label>
<input type="submit" value="Add to cart" name="item03">
</form>
</body>
</html>
내 카트 페이지에 대한 PHP 코드 :
<?php
session_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$max_items = $_SESSION['maxItems'];
for($i=0; $i <= $max_items; $i++){
$current_name = $_SESSION['cart'][$i]['name'];
$current_price = $_SESSION['cart'][$i]['price'];
echo "item is " . $current_name . " " . $current_price . "<br>";
}
?>
</body>
</html>
사용자가 양식을 제출하지 않은 경우에도 페이지로드에 있도록, html로에서 세션을 만들! – CMPS