SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I want to add multiple items to a shopping cart, at the same time.

    Hi Guys..
    I am setting a shopping cart and it works OK with BUY NOW buttons and adds the product to the cart one at a time.

    However, I want to select a few items, via checkboxes, and pass them to the cart.php all at the same time. The shopping cart has facility to change the quantities and update the cart.

    This is a chopped down version of the sending code:
    Code:
    		$main_content .= "<form action='cart/cart.php?action=add&id=$id' method='get' target='new'>";
    		if($color==1){
    		$main_content .= "<tr bgcolor='#ffcc99'>";
    // ORDERS 1
    		$main_content .= "<td valign='top'>$product <font color=#ff0000><b>$comments</b></font></td>";
    		$main_content .= "<td valign='top'>$packquantity</td>\n";
    		$main_content .= "<td valign='top'>&pound$trade</td>\n";
    
    		$main_content .= "<td valign='top'><input type='checkbox' name='id' value='$id'>\n";
     
    		$main_content .= "</tr>\n";
    
    
    		$main_content .= "<input type='submit' value='Place Order'>";
    		$main_content .= "&nbsp;&nbsp;&nbsp;&nbsp;<input type='reset' value='Clear'>";
    
    		$main_content .= "</form></form></td></tr></table>\n";
    The receiving code in my cart.php file is:
    Code:
    $cart = $_SESSION['cart'];  
    $action = $_GET['action'];  
    
    switch ($action) {  
        case 'add': 
            if ($cart) {  
                $cart .= ','.$_GET['id'];  
            } else {  
                $cart = $_GET['id'];  
            }  
    header("Location: cart.php"); 
            break;
    I think that the receiving code is wrong. It works OK for the BUY NOW button, one at a time, but it doesn't work for multiple additions.

    Can anybody help ???

    Thanks,

    John C

  2. #2
    SitePoint Wizard frank1's Avatar
    Join Date
    Oct 2005
    Posts
    1,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sooner or later i think you will need it so try to have array to store the values in cart
    and one next thing multiple values can go in checkbox so start using id[] in the form and remember it is multidimensional array when you access it so $_GET['id'] wont work but $_GET['id'][0] will.

    Thanks

  3. #3
    SitePoint Member
    Join Date
    Jun 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi frank1..

    Thank you for taking the time to reply to my query.
    However, I did figure it out, after a long time, and it is now working fine.

    Thank you,

    John C


Bookmarks

Posting Permissions

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