I am creating an ecommerce website for a project work, it will not be used live. I am having trouble deleting items from the shopping cart! please help me
This is to add items to the shopping cart:
$cart_row = array(
'item' => $item,
'unitprice' => $price,
'quantity' => $quantity
);
if (!isset($_SESSION['cart']))
$_SESSION['cart'] = array();
$_SESSION['cart'][] = $cart_row;
var_dump($_SESSION);
This is to display the shopping cart and I want a remove button, I think it's incorrect though.
if (!isset($_SESSION['cart']) || (count($_SESSION['cart']) == 0)) {
echo '<p>Your cart is empty.</p>';
} else {
echo '<table border="1">
<tr><th>Item</th><th>Unit price</th><th>No. of units</th><th>Subtotal</th></tr>';
$total = 0;
foreach($_SESSION['cart'] as $item) {
echo "<tr><td>{$item['item']} </td>
<td>\${$item['unitprice']}</td><td>{$item['quantity']}</td>
<td>$".($item['unitprice'] * $item['quantity'])."</td>
<td>. $items[$item] . ' (<a href="' . $_SERVER['PHP_SELF'] . '?remove=' . $item . '">Remove</a>) </td>
</tr>";
$total += ($item['unitprice'] * $item['quantity']);
}
echo '</table>';
echo "<p><strong>Grand total: </strong>\$$total</p>";
}
?>