Thursday 15 January 2015

php - Quantity Not adjusting -


I am trying to adjust the amount of an item when a user enters the quantity and clicks on the update But I have a problem to do this work when you have finished the volume and click on the update, it does nothing, my PHP code is below

PHP code

  & lt ;? Php start_session (); ? & Gt; & Lt ;? Php if (isset ($ _ POST ['item_to_adjust']) and $ _POST ['item_to_adjust']! = "") {$ Item_to_adjust = $ _POST ['item_to_adjust']; $ Quantity = $ _POST ['quantity']; $ Quantity = preg_replace ('# [^ 0-9] #i', '', $ quantity); If ($ quantity> = 100) {$ quantity = 99; } If ($ quantity & lt; 1) {$ quantity = 1; } If ($ quantity == "") {$ quantity = 1; } $ I = 0; In the form of foreach ($ _SESSION ["cart_array"] $ array_key = & gt; $ each_iit} {if ($ each_item ['item_id'] == $ pid and $ every_item ['item_to_adjust'] == $ item_to_adjust and Amp;; $ each_item ['length'] == $ length and $ every_item ['category'] == $ range) {$ _SESSION ["cart_array"] [$ array_key] ['quantity'] = $ quantity; $ Was right; = True; }}}? & Gt;   

form

  echo & lt; Form action = "cart.php" method = "post" & gt; & Lt; Input name = "volume" type = "text" value = "'. $ Each_item [' quantity '].'" Size = "1" maximum label = "2" /> & Lt; Input name = "adjustBtn '. $ Item_id.' 'Type = "submit" value = "update" />  gt; ';? & Gt;    

In my PHP code, if you want to work with a user , You must include session_start (); at your start. Php file

It also includes AJAX files. < P> If you call an Ajax from a php page which is session_start, this does not mean that the AJAX script will be "" Session. You need to session_start (); in Ajax script.

No comments:

Post a Comment