Jump to content

cart updation problem


Jaswinder
Go to solution Solved by mac_gyver,

Recommended Posts

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.

Link to comment
Share on other sites

@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 by Jaswinder
Link to comment
Share on other sites

  • Solution

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;
        }
    }
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.