Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Holding multiple sessions before submit ?

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi

I need some advice regarding a website I am developing at the moment.
Basically I have 3 steps

Step One
Step Two
Step Three

2 dropdowns in step one
2 dropdowns in step two
2 input text boxes in step three

Each of these options are converted to session variables when selected

Now here’s the problem when the user is finished step three they are brought to step four

Step four has 2 options

>> Register more products

>> Proceed to checkout

If the user would like to register more products then they revert back to step one
And choose more options.

My question is how can I hold multiple variables before I submit to the Database (MySQL)

Eg First time through

$_POST[‘prodcut1’]
$_POST[‘prodcut2’]
$_POST[‘prodcut3’]


Second time through

$_POST[‘prodcut1’] same variable name but different option
$_POST[‘prodcut2’] same variable name but different option
$_POST[‘prodcut3’] same variable name but different option

How can I hold all these variables until payment has be accepted
And then enter into the database

Basically how can I hold multiple copies of the same variable with different
Values and then insert into database

I hope you can understand this.

Thanks
 
I'm assuming that you are currently doing something like this to store the form input:
Code:
$_SESSION['product1'] = $_POST['product1'];

Since there is a chance that this form will be used more than once, you probably want to use an array for this:
Code:
$_SESSION['product1'][] = $_POST['product1'];

That's one way.

Ken
 
Tks Ken

Yes I am using $_SESSION['product1'] = $_POST['product1'];

so is it possible to insert into a database this way.

Will I have to use a for loop will it be something like this

for (some variable here)
{
INSERT $_SESSION['product1'][]
INTO etc,etc
}
 
Your for loop would look something like:
Code:
for ($i=0;$i<count$_SESSION['product1'];$i++) {
 $q = "insert into xyz set product1='" . $_SESSION['product1'][$i] . "'";
// etc...
}
Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top