シンプルなphpとmysqlコードでショッピングカートを作成したいのですが、カートを表示するコードが1つあります。ここで、各 iは、カートを作成し、seesionがあり、私はショッピングカートそれぞれのボタンを削除したアイテムを表示するカート
<?php
session_start();
include_once("config.php");
if(empty($_SESSION['cart']))
$_SESSION['cart'] = array();
if(isset($_POST['product_code'])){
\t \t $product_code = $_POST["product_code"];
\t \t $product_name = $_POST["product_name"];
\t \t $product_qty = $_POST["product_qty"];
\t \t $product_price = $_POST["price"];
\t \t $product_color = $_POST["product_color"];
\t \t $_SESSION['cart'][] = array('name' => $product_name, 'product_code' => $product_code, 'qnty' => $product_qty, 'color' =>$product_color, 'price' => $product_price);
\t \t
\t \t
\t \t
}
print_r ($_SESSION['cart']);/*header("Location: view_cart.php");*/
if(isset($_POST['empty']) ){
unset($_SESSION["cart"]);
\t \t \t
\t }
\t
\t
?>
<html>
<head>
</head>
<body>
<form method="POST" action="cart.php"><div align="center"><button type="remove" name="empty" >empty</button></div>
<a href="ppage.php">back </a>
<table width="100%" cellpadding="6" cellspacing="0"><thead><tr><th>Quantity</th><th>Name</th><th>Price</th><th>code</th><th>colour</th><th>remove</th></tr></thead>
<tbody>
<?php
foreach($_SESSION['cart'] as $itm=>$val)
\t echo "<thead>";
\t \t echo"<tr>";
\t \t \t echo '<td>'.$val['$qnty'].'</td>';
\t \t \t echo '<td>'.$val['name'].'</td>';
\t \t \t echo '<td>'.$val['price'].'</td>';
\t \t \t echo '<td>'.$val['product_code'].'</td>';
\t \t \t echo '<td>'.$val['color'].'</td>';
\t \t \t /*echo '<td>'<a href="?remove=<?php echo $itm; ?>">remove</a>'</td>'
\t \t \t \t */
\t \t \t \t
\t \t \t \t if (isset($_POST['remove'])){
\t
\t \t \t \t unset($_SESSION['cart'][$_POST['remove']]);}
\t \t \t /*echo \t <div align="right"><button type="remove" name="remove" >remove</button></div> */
\t \t \t echo '</tr>';
\t \t \t echo "<thead>";
\t
\t \t \t
\t \t ?> \t
echo \t <div align="right"><button type="remove" name="remove" >remove</button></div>
\t \t \t \t echo '<td>'<a href="?remove=<?php echo $itm; ?>">remove</a>'</td>'
\t \t \t \t \t
</form>
</tbody>
</body>
</html>
あなたの説明に句読点を使用してください:
だからあなたのコードは次のようにする必要があります。すべてのものが1つの文に含まれているときに読むのは本当に難しいです。 –
今質問を編集することはできません –