Jump to content

cart updation problem


Jaswinder

Recommended Posts

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

post-144975-0-29137900-1379788216_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/282343-cart-updation-problem/
Share on other sites

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.

@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

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;
        }
    }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.