|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
I've been having a problem building a basic shopping cart, which is modelled after the "persistent shopping cart" tutorial. It works fine, however, every time I hit the "refresh" button on my Web browser, it adds an additional item to the cart (but only when the quantity is set to 1, if I set it higher it won't add it). The code is below. Can anyone tell me what I'm doing wrong, I'm not sure what I'm seeing. The cart.php code PHP Code:
and here's the ShowCart() function in the include file functions.php PHP Code:
|
|
#2
|
|||
|
|||
|
Whenever you click on a link, the browser sends a request to the server.
If you hit refresh, the browser sends a new request to the server. So the shopping cart gets 2 commands to add the product. That's why new stuff is added. I didn't read all of your code, so just say if I missed something. |
|
#3
|
|||
|
|||
|
The problem is most likely in the AddItem method. Please post the code for that method so we can see what the issue is.
|
|
#4
|
|||
|
|||
|
Okay, here's the AddItem() function, along with UpdateItem():
PHP Code:
|
|
#5
|
|||
|
|||
|
If you take off the error suppression (the @ sign in front of your mysql_query call), does the page return an error when the qty is greater than 1?
|
|
#6
|
|||
|
|||
|
No, I don't get any errors when I remove the @, but if I add another item in the cart when there's already a quantity, it doesn't up the quantity, it just adds that item on a different line. I can have a qty of 3 on the 1st line and a qty of 1 on the 2nd.
|
|
#7
|
|||
|
|||
|
Does the cart table have a primary key on cookie_id and item_id? If it does, I don't see how you can insert 2 lines into the table with the same cookie_id and item_id, but different quantities...
Check the table to see that the primary key exists... Also, your update_item function is not incrementing the qty by the qty passed to it, but simply replacing the quantity that's in the table already. Is that the desired functionality? If not, change the SQL to read UPDATE cart SET qty=qty + $qty WHERE cookie_id = " . GetCartID() . " and item_id = $item_id HTH |
|
#8
|
|||
|
|||
|
hi
i also had the same problem. what you have sugessted has fixed it a bit. what happens when i add item from product.php, it increases the quantity. but when i try to change the quantity from cart.php using the combo box, this doesnt work. thanks |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > shopping cart problem (newbie) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|