LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-21-2012, 10:20 AM   #1
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Rep: Reputation: 1
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
 
Old 06-21-2012, 11:17 AM   #2
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
well, not exactly help but
free e-commerce software ?
 
Old 06-21-2012, 02:31 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
One suggestion is to use arrays for your checkboxs. Here is a simple example:

http://www.kavoir.com/2009/01/php-ch...-an-array.html
 
Old 06-21-2012, 05:59 PM   #4
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 127

Original Poster
Rep: Reputation: 1
Hi michaelk..

Thank for your suggestion.
I had already changed to using arrays by adding [] after 'name = 'id'
It now reads:
Code:
$main_content .= "<td valign='top'><input type='checkbox' name='id[]' value='$id'>\n";
At the receiving end, cart.php, when I use:
Code:
print_r ($_POST['id']);
exit;
I get all the values of the array.

It is this next part where I get stuck.
My cart.php is:
Code:
switch ($action) {  
    case 'add':  
        if ($cart) {  
            $cart .= ','.$_GET['id'];  
        } else {  
            $cart = $_GET['id'];  
        }  
header("Location: cart.php"); 
        break;
and it doesn't handle the array.
This is where I need the help.

John C
 
Old 06-21-2012, 06:23 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,702

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
You need to loop through the array and suggest using a foreach loop similar to this thread.

http://www.linuxquestions.org/questi...in-php-947784/
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need a shopping cart software? rblampain Linux - Software 1 11-04-2011 07:26 AM
How to write a shopping cart in PHP resetreset Programming 4 02-02-2010 03:08 AM
suggest a shopping cart ? nephish Linux - Software 3 12-18-2005 01:55 PM
shopping cart?? jme General 1 06-05-2004 10:07 AM
Shopping cart for linux graystarr Linux - Distributions 1 07-25-2002 04:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration