Jaswinder Posted September 21, 2013 Share Posted September 21, 2013 friends.. when i update the cart.. it get updated ,, but still it shows a error Notice: Undefined index: quantity- in C:\xampp\htdocs\cart\cart.php on line 16 i am attaching my files with this topic.. have a look .. and try to update it cart.php connection.php index.php products.php reset.css style.css Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/ Share on other sites More sharing options...
vinny42 Posted September 22, 2013 Share Posted September 22, 2013 Did you google the error? Because it is pretty self explanatory; you are looking for an element of an array and that element does not exist. Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450632 Share on other sites More sharing options...
mac_gyver Posted September 22, 2013 Share Posted September 22, 2013 when you did the print_r() of the post data, i'm willing to bet it didn't have any data that exactly matched what the code is trying to process. could you copy/paste the output from the print_r($_POST) statement? i was going to comment in your previous thread, that the $_SESSION['cart'] variable was designed properly. too bad the form fields weren't. there's no need for that amount of complicated code to do this. the form field should be an array name so that the data it submits will be an array and be exactly in the same format as the $_SESSION['cart'] array. Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450652 Share on other sites More sharing options...
Jaswinder Posted September 22, 2013 Author Share Posted September 22, 2013 (edited) @mac_gyver .. i have added two products.. and it added properly to the cart.. but on cart page whenever i update the quantity it shows that error... as you asked , here is the output of print_r($_POST) Array ( [quantity-2] => 2 [quantity-1] => 1 [submit] => Update ) the quantity- is there, dont know why it say so... i have provided the files.. will you please download them an try to run on your system.. and also if u think that these codes are complicated , fetch me some easy on .. Thanks for reply Edited September 22, 2013 by Jaswinder Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450665 Share on other sites More sharing options...
Jaswinder Posted September 22, 2013 Author Share Posted September 22, 2013 hey friends i just made some changes to the cart.php... now the cart is working great... however.. i still looking for @mac_gyver reply.. If u can tell me some easy set of code for the cart. Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450667 Share on other sites More sharing options...
Solution mac_gyver Posted September 22, 2013 Solution Share Posted September 22, 2013 the form field for the quantity should be - <td><input type="text" name="quantity[<?php echo $f['id_products'];?>]" size="5" value="<?php echo $_SESSION['cart'][$f['id_products']]['quantity'];?>" /></td> the corresponding code that would use the submitted quantity data would be - if(isset($_POST['submit'])) { foreach($_POST['quantity'] as $key => $value) { if($value <= 0) { unset($_SESSION['cart'][$key]); } else if($value > 50 ) { $_SESSION['cart'][$key]['quantity'] = 50; } else { $_SESSION['cart'][$key]['quantity'] = $value; } } } Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450671 Share on other sites More sharing options...
Jaswinder Posted September 22, 2013 Author Share Posted September 22, 2013 thanks buddy Quote Link to comment https://forums.phpfreaks.com/topic/282343-cart-updation-problem/#findComment-1450673 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.