Jump to content

Eddietse91

Members
  • Posts

    3
  • Joined

  • Last visited

Eddietse91's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Can anyone help me please?
  2. Sorry about that, <?php $cart_row = array( 'item' => $item, 'unitprice' => $price, 'quantity' => $quantity ); if (!isset($_SESSION['cart'])) $_SESSION['cart'] = array(); $_SESSION['cart'][] = $cart_row; var_dump($_SESSION); ?> <?php 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>"; } ?>
  3. 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>"; } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.