Results 1 to 5 of 5

Thread: Problem with shopping cart (session)

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Problem with shopping cart (session)

    I store item_id and qty into an array ($_SESSION[item_id] & $_SESSION[qty]), but I have a big problem.
    When I add the first item and trying to add one more, the second one deletes the first and takes its place.
    Please tell me some suggestions to solve this problem! SOS!!!

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem with shopping cart (session)

    The reason why isbecuase you are not making them arrays. Why you add an item use this method:
    PHP Code:
    <?php
    function add_item($new_itemid$new_qty)
    {
        
    $_SESSION['itemid'][] = $new_itemid;
        
    $_SESSION['qty'][] = $new_qty;
    }
    ?>
    I would suggest you change your approach and have an array of item objects like this:
    PHP Code:
    class Item
    {
        var 
    $id;
        var 
    $price;
        var 
    $qty;

        function 
    Item($id$price$qty)
        {
            
    $this->id $id;
            
    $this->price $price;
            
    $this->qty $qty;
         }
    }

    function 
    add_item(& $item)
    {
        
    $_SESSION['cart_items'][] = & $item;
    }

    /* example */
    $item = new Item('Mars Bar'0.552);

    add_item($item); 
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Re: Problem with shopping cart (session)

    visualAD:
    can you post the full code?
    I'm stuck...

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem with shopping cart (session)

    I haven't got full code. I just made that out of my head. What is it you are stuck on?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    3

    Re: Problem with shopping cart (session)

    Problem solved!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width