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

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

shopping cart delete item

Post by terrenuit »

Hi,
my shopping cart script has a problem:
if I have serveral items, when I want to delete the last or second....last item,
it is always the first item has been delete,
I cannot delete the item that I want.
I wish someone can help me,
it is my script:

<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?name=<?php print $product['ref'] ?>"></map>
phpdeveloper1
Forum Newbie
Posts: 19
Joined: Tue Aug 12, 2014 6:13 am
Location: Chennai, India

Re: shopping cart delete item

Post by phpdeveloper1 »

terrenuit wrote:...............Hi,
my shopping cart script has a problem:
.........................................
Which shopping cart script are you using ?
Chris, Php Developer and Programmer,
https://www.phpfreelanceprogrammer.com/
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

@phpdeveloper1
I created my shopping cart by myself, on part script is:
<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?name=<?php print $product['ref'] ?>"></map>
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 »

Wow. I haven't seen an area map used since literally the 90s. That said, it would be helpful to see some of the surrounding code. Have you confirmed that cancel.php is working correctly? Tried it with both good values and bad?
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

@Celauran
yes, the cancel.php work correctly, but only for one item,
if there's serveral items, and I want to cancel the last or second last item, it is the first item has been cancelled.

<td align="center"><?php print $product['ref'] ?></td>
<td><?php print $product['price'] ?>€</td>
<td align="center"><?php print $product['quantity'] ?></td>
<td align="center"><?php print($product['quantity']*$produit['prix'])?>€</td>
<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?ref=<?php print $product['ref'] ?>"></map>
</td>
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 »

Code: Select all

<td align="center"><?php print $product['ref'] ?></td>
<td><?php print $product['price'] ?>€</td>
<td align="center"><?php print $product['quantity'] ?></td>	
<td align="center"><?php print($product['quantity']*$produit['prix'])?>€</td>	
<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?ref=<?php print $product['ref'] ?>"></map> 
</td>
This is being executed within a loop? It looks correct at a glance, but it's hard to say for certain. I suspect cancel.php is where the problem lies, especially when you say things like this:
terrenuit wrote:yes, the cancel.php work correctly, but only for one item,
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

if I replace
<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?ref=<?php print $product['ref'] ?>"></map>

by
<td> <a href="supprimer.php?ref=<?php print $product['ref'] ?>">cancel</a></td>
it is all right, I can cancel the item as I want,
so, I d'ont understand why ?
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 »

Supprimer.php and cancel.php contain the exact same code?
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

yes, excuse me I forgot to change it
<td> <a href="cancel.php?ref=<?php print $product['ref'] ?>">cancel</a></td>
borre
Forum Newbie
Posts: 10
Joined: Thu Oct 02, 2014 7:21 am

Re: shopping cart delete item

Post by borre »

Can we see the cancel.php ?

The problem might be right there.

But if you have troubles with using the area map, maybe might consider just using modern coding and forget about the map tags.. :p
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

yes, it is the cancel.php:
<?php
session_start();
require_once 'panier.php';
$panier = new Panier('produits');
$panier->delete($_GET['name']);

header('location: cart.php');
?>
I prefer the garbage than the word "cancel", because it is more beautiful
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 »

terrenuit wrote:I prefer the garbage than the word "cancel", because it is more beautiful
You can certainly use an image in a link without resorting to an image map. Bootstrap's glyph icons, FontAwesome, etc. Plus just regular old images.
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 »

Code: Select all

href="cancel.php?ref=<?php print $product['ref'] ?>"
but then

Code: Select all

$panier->delete($_GET['name']);
You've got 'ref' in one place and 'name' in another. That's definitely a problem.
terrenuit
Forum Commoner
Posts: 53
Joined: Tue Jul 08, 2014 2:18 pm

Re: shopping cart delete item

Post by terrenuit »

yes, you are right, if I put

$panier->delete($_GET['ref']);
my site works correctly,
but If I put the picture( garbage), it doesn't work. I d'ont understand why I cannot replace the word " cancel" by the picture ?

<td align="center" > <img src="photos/garbage.jpg" width="23" height="40" border="0" usemap="#Map"> <map name="Map">
<area shape="rect" coords="2,0,34,47" href="cancel.php?ref=<?php print $product['ref'] ?>"></map>
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 »

Code: Select all

<a href="cancel.php?ref=<?= $product['ref']; ?>"><img src="photos/garbage.jpg"></a>
That doesn't work?
Post Reply