shopping cart delete item

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

shopping cart delete item

Post 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";?>€
Last edited by Celauran on Thu Aug 21, 2014 7:14 am, edited 1 time in total.
Reason: Please wrap your code in syntax tags. Makes it much easier to read.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: shopping cart delete item

Post 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'].
Post Reply