我想用簡單的PHP和MySQL代碼創建購物車這裏是一個代碼來查看購物車,我想看到在一個表中的項目和刪除按鈕爲這裏每個 我創建了一個車,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>
請您說明使用標點符號。當每一句話都在一個句子中時,真的很難讀懂。 –
現在我不能編輯的問題 –