FairyBusiness
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
How do I pull everything from the form??
(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);
}
}
How do I pull everything from the form??
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got this back:
Notice: Undefined index: quantity in /hermes/web09c/b2950/moo.a uroriellac om/include s/library. php on line 422
Array
(
[b3] =>
[b4] => 1
)
also it got rid of my b3 qty!
Notice: Undefined index: quantity in /hermes/web09c/b2950/moo.a
Array
(
[b3] =>
[b4] => 1
)
also it got rid of my b3 qty!
ASKER
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!
ASKER
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. ..
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]
should be $_POST['qty'][$item]
ASKER
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>';
}
}
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.
ASKER
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!
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!
ASKER
It works :)) Thanks!
ASKER
ok maybe you can help me with my next question: removing an item from the shopping cart
$cart = $_SESSION['cart'];
put:
$_SESSION['cart'][$item]=$