Link to home
Start Free TrialLog in
Avatar of FairyBusiness
FairyBusinessFlag for United States of America

asked on

How to make all items of my shopping cart legit for being updated?

Hi, I have a shopping cart that I am trying to update:

(add stuff first)

http://www.auroriella.com/bracelet.php?item=b3
http://www.auroriella.com/bracelet.php?item=b4

shopping cart:

http://www.auroriella.com/show_cart.php

well it only updates the first item in the shopping cart, bc its only pulling the first row of stuff from it

function updateCart() {
	if((isset($_POST['update'])) && (!empty($_POST['qty'])) && (!empty($_POST['item']))) {
		$item = trim(mysql_clean_strings($_POST['item']));
		var_dump($item);
		echo "<p>";
		$qty = trim(mysql_clean_strings($_POST['qty']));
		var_dump($qty);
		echo "<p>";
		$cart = $_SESSION['cart'];
		$cart[$item] = $qty;
		var_dump($cart);
	}
}

Open in new window


How do I pull everything from the form??
Avatar of hielo
hielo
Flag of Wallis and Futuna image

BEFORE:
$cart = $_SESSION['cart'];

put:
$_SESSION['cart'][$item]=$qty;
Avatar of FairyBusiness

ASKER

nope its still just updating the first one.  I think because its only pulling one item and one qty from the form?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I got this back:

Notice: Undefined index: quantity in /hermes/web09c/b2950/moo.auroriellacom/includes/library.php on line 422

Array
(
    [b3] =>
    [b4] => 1
)


also it got rid of my b3 qty!
oh I forget to change quantity to qty.  I just did and its back to where we were before.  It updates the first one only
it seems to work ok for me!
You added both of these to the shopping cart?

http://www.auroriella.com/bracelet.php?item=b3
http://www.auroriella.com/bracelet.php?item=b4

and then tried to update both?  bc its only letting me update the top one. ..
>>$_POST['quantity'][$item]
should be $_POST['qty'][$item]
This is what I have:

function updateCart() {
	if((isset($_POST['update'])) && (!empty($_POST['qty'])) && (!empty($_POST['item']))) {
                /*
		$item = trim(mysql_clean_strings($_POST['item']));
		var_dump($item);
		echo "<p>";
		$qty = trim(mysql_clean_strings($_POST['qty']));
		var_dump($qty);
		echo "<p>";
		$cart = $_SESSION['cart'];
		$cart[$item] = $qty;
		var_dump($cart);
                */
                foreach($_POST['item'] as $item)
                {
                   $item=trim(mysql_clean_strings($item));
                   $qty=trim(mysql_clean_strings($_POST['qty'][$item]));
                   $_SESSION['cart'][$item]=$qty;
                }
                echo '<pre>'.print_r($_SESSION['cart'],true).'</pre>';
	}
}

Open in new window

you are sending one <FORM> per row. The browser can submit only one form at a time.  You need to use ONE <form> tag and it needs to be "Wrapped" around your entire table.
I put it like that for the delete buttons. . .  I'm not sure how else to delete otherwise!
if you have <input name="delete['b3]" type="submit" value="Delete">

when you press it, you will be able to see/detect delete['b3'] ($_POST['delete']['b3']). When you detect it, delete it!

And stop drowning in a glass of water!
It works  :))  Thanks!
ok maybe you can help me with my next question:  removing an item from the shopping cart