Page 1 of 1

shopping cart delete item

Posted: Thu Aug 21, 2014 4:22 am
by terrenuit
Hi,
I have a shopping cart script, which can calcalate the total and subtotal price, no problem,
now, I want to delete one or more items, but it doesn't work, I wish someone can help me, please!

delete.php

Code: Select all

<?php
session_start();
if(isset($_SESSION['name'])) unset($_SESSION['name']);
header('location: view_cart.php');
?>
view_cart.php

Code: Select all

<?php 
       $totalprice=0;
       foreach($listproduit as $produit) {            
       $subtotal=$produit['quantity']*$produit['price'];
       $totalprice+=$subtotal;
       ?>  
	<tr>
	   <td><?php print $produit['name'] ?></td>
	   <td><?php print $produit['price'] ?></td>
	   <td><?php print $produit['quantity'] ?></td>	  
        <td><?php print($produit['quantity']*$produit['price'])?>€</td>	 
        <td> <a href="delete.php?name=<?php print  $produit['name'] ?>">delete</a></td>	
	</tr>	
	<?php } ?>
    <?php echo "Total: $totalprice";?>€

Re: shopping cart delete item

Posted: Thu Aug 21, 2014 7:16 am
by Celauran
Looks like you're storing shopping cart items in session data and then passing the name of the item to delete as a query string. In that case, you first need to check for $_GET['name'].