0

Hello,

I am trying to update my PHP CART without having the page refreshed!

Here is a part of my code... I will just use the UPDATE_QUANTITY part (there are ADD & Remove)

My Form that holds the quantity:

<form name="upd_itm" id="upd_itm" action="cart_function.php" method="post">
<span class="text"><input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" style="text-align: center;"/>
<br />
<button name="adjustBtn' . $item_id . '" id="adjustBtn' . $item_id . '" type="submit" class="avoid_ref" value=""><img src="bttn_pics/change_value.png" /></button>
<input name="item_to_adjust" id="item_to_adjust" type="hidden" value="' . $item_id . '" /></span>
</form>

My action.php that proccess it

if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") {
    // execute some code
	$item_to_adjust = $_POST['item_to_adjust'];
	$quantity = $_POST['quantity'];
	$quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers
	if ($quantity >= 100) { $quantity = 99; }
	if ($quantity < 1) { $quantity = 1; }
	if ($quantity == "") { $quantity = 1; }
	$i = 0;
	foreach ($_SESSION["cart_array"] as $each_item) { 
		      $i++;
		      while (list($key, $value) = each($each_item)) {
				  if ($key == "item_id" && $value == $item_to_adjust) {
					  // That item is in cart already so let's adjust its quantity using array_splice()
					  array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity)));
				  } // close if condition
		      } // close while loop
	} // close foreach loop
}

Can I make it update my quantity in that Quantity text field?????

Thank you

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by divyakrishnan
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.