Ok it seems there was some problems last time I posted (sorry about that guys) so Ill give it another shot. I am creating a form which is 3 pages long (step1.php, step2.php, and step3.php) then after all the forms are filled out I need to display all the data on a "final.php" page so the visitor can double check their input for errors and if any errors, beable to correct them (via back button) and if not, submit the forms and enter the data into the db. With that said here is some snippets of my forms...
This is "step1.php"
[PHP]<form name="step1" method="post" action="basic2.php">
<?php include ('db_scripts/db_connect_insert.php'); ?>
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="2"><b>Please enter a valid e-mail address. You will need to confirm your e-mail address to activate your account.</b>
</td>
...
<td class="required">Company Name</td>
<td class="required"><input type="text" name="comp_name" size="20" maxlength="15" /></td>
...
<td class="required">Establishment Type</td>
<td class="required">
<select name="comp_type">
<option selected>- Select One -</option>
<option value="bars">Bar</option>
<option value="clubs">Club</option>
<option value="coffee_shops">Coffee Shop</option>
<option value="resturants">Resturant</option>
</select>
</td>
...
<td class="required">Address</td>
<td class="required"><input type="text" name="comp_address" size="30" maxlength="30" /></td>
...
<td class="required">Phone Number</td>
<td><input type="text" name="comp_phone" size="20" maxlength="40" /></td>
...
<td class="required">Email Address</td>
<td><input type="text" name="comp_email" size="30" maxlength="20" /></td>
...
<td class="required">Website Address</td>
<td><input type="text" name="comp_web" size="30" maxlength="20" /></td>
...
<td class="required">Description</td>
<td><textarea name="comp_desc" cols="30" rows="12"></textarea></td>
...
<td class="verdana11" align="right" width="125"><p></td>
<td><input onClick="basic2.php" type="submit" name="submit" value="Go to step 2" /></td>
</tbody>
</table>
</form>[/PHP]
and here is "step2.php"
[PHP]<div align="left"><h2><font color="#b80101">Types of Cuisine</font></h2></div>
<fieldset align="center">
<table>
<tr>
<td><input type="checkbox" id="foods[]" name="afghan"/></td><td>Afghan</td>
<td><input type="checkbox" id="foods[]" name="caribbean"/></td><td>Caribbean</td>
<td><input type="checkbox" id="foods[]" name="greek"/></td><td>Greek</td>
<td><input type="checkbox" id="foods[]" name="korean"/></td><td>Korean</td>
<td><input type="checkbox" id="foods[]" name="pizza"/></td><td>Pizza</td>
<td><input type="checkbox" id="foods[]" name="swedish"/></td><td>Swedish</td>
</tr>
<tr>
<td><input type="checkbox" id="foods[]" name="american"/></td><td>American</td>
<td><input type="checkbox" id="foods[]" name="chinese"/></td><td>Chinese</td>
<td><input type="checkbox" id="foods[]" name="indian"/></td><td>Indian</td>
<td><input type="checkbox" id="foods[]" name="lebanese"/></td><td>Lebanese</td>
<td><input type="checkbox" id="foods[]" name="peruvian"/></td><td>Peruvian</td>
<td><input type="checkbox" id="foods[]" name="sweets"/></td><td>Sweets</td>
</tr>
<tr>
<td><input type="checkbox" id="foods[]" name="appetizers"/></td><td>Appetizers</td>
<td><input type="checkbox" id="foods[]" name="cuban"/></td><td>Cuban</td>
<td><input type="checkbox" id="foods[]" name="irish"/></td><td>Irish</td>
<td><input type="checkbox" id="foods[]" name="mediterranean"/></td><td>Mediterranean</td>
<td><input type="checkbox" id="foods[]" name="portuguese"/></td><td>Portuguese</td>
<td><input type="checkbox" id="foods[]" name="thai"/></td><td>Thai</td>
</tr>
<tr>
<td><input type="checkbox" id="foods[]" name="brazilian"/></td><td>Brazilian</td>
<td><input type="checkbox" id="foods[]" name="french"/></td><td>French</td>
<td><input type="checkbox" id="foods[]" name="italian"/></td><td>Italian</td>
<td><input type="checkbox" id="foods[]" name="mexican"/></td><td>Mexican</td>
<td><input type="checkbox" id="foods[]" name="southwestern"/></td><td>South Western</td>
<td><input type="checkbox" id="foods[]" name="turkish"/></td><td>Turkish</td>
</tr>
<tr>
<td><input type="checkbox" id="foods[]" name="cajun&creole"/></td><td>Cajun & Creole</td>
<td><input type="checkbox" id="foods[]" name="german"/></td><td>German</td>
<td><input type="checkbox" id="foods[]" name="japanese"/></td><td>Japanese</td>
<td><input type="checkbox" id="foods[]" name="middle_eastern"/></td><td>Middle Eastern</td>
<td><input type="checkbox" id="foods[]" name="spanish"/></td><td>Spanish</td>
<td><input type="checkbox" id="foods[]" name="vietnamese"/></td><td>Vietnamese</td>
</tr>
</table>
</fieldset>
<input onClick="basic3.php" type="submit" name="submit" value="Go to step 3" />[/PHP]
Now last time I posted this I also added the third form but there was to much code posted here so the post had to get deleted. If this has to get deleted ill take an attempt to make the in here much shorter and simplified. Anyway what I am looking for cuz im such a noob, is to set these forms up with sessions and to do the db insert query when needed as described in the first paragraph. Thank you all so much in advance for your help.
35 3041
Heya, Crazy8. Welcome (back) to TSDN!
What you'll want to do here is create an array in your session and then copy $_POST values to it. At the end of step 3, you can then execute the query. -
foreach( $_POST as $__key => $__val )
-
{
-
$_SESSION['form'][$__key] = $__val;
-
}
-
The above code will copy every value in $_POST into $_SESSION['form']. Use this when processing the User's input.
So then, to make sure I understand correctly I just have a few questions?
1) All I do is put that code at the top of each form and thats it?
2) I still need to do session_start() at the top, correct?
3) To echo this onto page 4 so the visitor can see everything they typed all I need to do in my script is echo $_SESSION['form'][$_key] ?
4) would I need to do anything special as far as my "back" buttons go with allof this?
thanks for the help I greatly appreciate it.
Heya, Crazy8.
1) All I do is put that code at the top of each form and thats it?
More or less. You'd only need to put this at the top of any page that processes User input. In other words, if you had page1.php, page2.php, page3.php and page1process.php, page2process.php and page3process.php, you'd only need to put this code at the top of page1process.php, page2process.php and page3process.php.
2) I still need to do session_start() at the top, correct?
Correct.
3) To echo this onto page 4 so the visitor can see everything they typed all I need to do in my script is echo $_SESSION['form'][$_key] ?
More or less. You'd just substitute $_key with the input's name. For example: -
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['name']) ) echo $_SESSION['form']['name']; ?>" />
-
4) would I need to do anything special as far as my "back" buttons go with allof this?
Not specifically. The session would be updated only when the User submits a form, so he can go back/forward as much as he likes, and no changes will be made until he submits something.
if you had page1.php, page2.php, page3.php and page1process.php, page2process.php and page3process.php, you'd only need to put this code at the top of page1process.php, page2process.php and page3process.php.
I dont actually have any scripts that process the form(s). Do I need anything else other then the session stuff and the inserting of the data into the db?
How do I take the session and insert the data into my db on the final submition?
So if I have this right (sorry for my noobiness) what I need to do is this...
[PHP]session_start()
foreach( $_POST as $__key => $__val )
{
$_SESSION['form'][$__key] = $__val;
}
<form name="step1" method="post" action="basic2.php">
<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tbody><tr>
<td colspan="2"><b>Please enter a valid e-mail address. You will need to confirm your e-mail address to activate your account.</b>
</td>
</tr>
<tr>
<td class="required">Company Name</td>
<td class="required"><input type="text" name="comp_name" size="20" maxlength="15" /></td>
</tr>
<tr>
<td class="required">Establishment Type</td>
<td class="required">
<select name="comp_type">
<option selected>- Select One -</option>
<option value="bars">Bar</option>
<option value="clubs">Club</option>
<option value="coffee_shops">Coffee Shop</option>
<option value="resturants">Resturant</option>
</select>
</td>
</tr>
<tr>
<td class="required">Address</td>
<td class="required"><input type="text" name="comp_address" size="30" maxlength="30" /></td>
</tr>
<tr>
<td class="required">Phone Number</td>
<td><input type="text" name="comp_phone" size="20" maxlength="40" /></td>
</tr>
<tr>
<td class="required">Email Address</td>
<td><input type="text" name="comp_email" size="30" maxlength="20" /></td>
</tr>
<tr>
<td class="required">Website Address</td>
<td><input type="text" name="comp_web" size="30" maxlength="20" /></td>
</tr>
<tr>
<td class="required">Description</td>
<td><textarea name="comp_desc" cols="30" rows="12"></textarea></td>
</tr>
<tr>
<td class="verdana11" align="right" width="125"><p></td>
<td><input onClick="basic2.php" type="submit" name="submit" value="Go to step 2" /></td>
</tr>
</tbody>
</table>
</form>[/PHP]
Notice I added the session_start() and the snipet to the form code, I did that IF I dont need some "processing"script for my forms. If thats the case then I just add the sessio_start() and the little snipet to the tops of each of my forms correct?
Thanks alot, again, for your help.
Heya, Crazy8.
That should do it.
Once the User submits step 3, you can then pull the saved values from $_SESSION['form'] and build your SQL query.
One other question I had is how would I account for check boxes if I wanted those to be in the session to? Or does this just grab everything?
Also maybe I am puttin my stuff in the wrong area im not sure but here is what I have done as of now...
[PHP]<?php
//session_start()
foreach( $_POST as $__key => $__val )
{
$_SESSION['form'][$__key] = $__val;
}
?>
<form name="step1" method="post" action="basic2.php">
...
...
...[/PHP]
Now I know I need the session_start() uncommented but for some reasn I was getting an error with it on and everything seems to be fine when its off, so I have that bit of code there pasted above my 3 forms. So now I made a 4th page to echo out everything and I cant get that to work. Here is what I have for that...
[PHP]<?php
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_name']) ) echo $_SESSION['form']['comp_name']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_type']) ) echo $_SESSION['form']['comp_type']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_address']) ) echo $_SESSION['form']['comp_address']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_phone']) ) echo $_SESSION['form']['comp_phone']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_email']) ) echo $_SESSION['form']['comp_email']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_web']) ) echo $_SESSION['form']['comp_web']; ?>" />
<textarea name="comp_desc" value="<?php if( isset($_SESSION['form']['comp_desc']) ) echo $_SESSION['form']['comp_desc']; ?>"> </textarea>
?>[/PHP]
And I get this error...
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\viewable\hsrevised\live\step4.php on line 2
Now if I am doing it right, I still get the error even if I write out each line like this...
echo '<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_name']) ) echo $_SESSION['form']['comp_name']; ?>" />';
Any thoughts as to what I am doing wrong?
Thanks again
Heya, Crazy8.
You're missing a semicolon after session_start().
ok well i got that now (I do know about the semi colon, just must have missed it) but after fixing it I got an error so I thought maybe I had the code in the wrong spot so I moved it into the <head></head> area on page1 and everything is fine but then when I hit submit and goto page2 I get the error again which is this...
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\xampp\htdocs\viewable\hsrevised\live\basic2.php :5) in C:\xampp\htdocs\viewable\hsrevised\live\basic2.php on line 6
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\viewable\hsrevised\live\basic2.php :5) in C:\xampp\htdocs\viewable\hsrevised\live\basic2.php on line 6
Now I am supposed to have this posted on all 3 forms right?
[PHP]<?php
session_start();
foreach( $_POST as $__key => $__val )
{
$_SESSION['form'][$__key] = $__val;
}
?>[/PHP]
Heya, Crazy8.
session_start() requires a couple of HTTP headers, which can only be sent before your script outputs anything.
Make sure you call session_start() at the very start of your script, before it outputs anything, including whitespace.
Ok I went and fixed that and ran through all three forms. Now I didnt get any errors untill the end but its with the pages that will be displaying the data that was entered. Here is the error I got...
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\viewable\hsrevised\live\step4.php on line 2
This is the code I have for the page to display the data. This is just for the data off step1.php..
[PHP]<?php
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_name']) ) echo $_SESSION['form']['comp_name']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_type']) ) echo $_SESSION['form']['comp_type']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_address']) ) echo $_SESSION['form']['comp_address']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_phone']) ) echo $_SESSION['form']['comp_phone']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_email']) ) echo $_SESSION['form']['comp_email']; ?>" />
<input name="name" type="text" value="<?php if( isset($_SESSION['form']['comp_web']) ) echo $_SESSION['form']['comp_web']; ?>" />
<textarea name="comp_desc" value="<?php if( isset($_SESSION['form']['comp_desc']) ) echo $_SESSION['form']['comp_desc']; ?>"> </textarea>
?>[/PHP]
Any thoughts what went wrong?
Heya, Crazy8.
Get rid of the enclosing PHP tags, and you should be good to go.
Ok now I am getting somehwere. Only now I am able to get through all 3 forms with now errors (as mentioned before) and now "page4" is isplayed but it only displayes the input boxes and not the data that should be inthem.
Got my issue figured out now. Just need to figure the sql insert stuff.
Thanks again
One thing I have noticed and cant seem to figure out is, I have created a "back button" of sorts that is on page4 where ALL the form dat gets displayed. Once I make it that far and I hit the back button (which is linked to step1) it does take me to step1 but with a whole new blank page and not a page with the data I had entered.
Any thoughts on why that would be?
Thanks
Heya, Crazy8.
Change the names of your inputs to match the variable names: -
<input name="--> comp_name <--" ... value="<?php if( isset($_SESSION['form']['--> comp_name <--']) ) echo $_SESSION['form']['--> comp_name <--']; ?>" />
-
I just realised that I had to fix that in my step4 and step1 files. So it is now working. So I do have just a few more questions and I think then i should be out of your hair ;D
1) How can i set an expire time on the session?
2) My "description" textarea isnt working as far as being added to the session, do I need to add it to the session differently and if so how?
3) I have a bunch of check boxes I also need to add tot he session. How would I do that?
I think thats it.
Thanks you so very much for your help and patients.
Crazy8
Well I think I found my solution to question one. Does anyone have any ideas about question 2 and 3?
Thanks alot
Heya, Crazy8.
#2: Textareas handle values a wee bit differently: -
<textarea ...>Value goes inside the tags.</textarea>
-
#3: Checkboxes are a pain in the butt. If the checkbox is checked, it appears in the $_POST array with a value of 'ON', but if the checkbox is unchecked, it doesn't show up in $_POST at all!.
There are several possible solutions; the easiest one is a bit kludgy, but then checkboxes are a bit kludgy: -
foreach( array('comp_check1', 'names_of', 'checkboxes', 'go_here') as $__key )
-
{
-
$_SESSION['form'][$__key] = isset($_POST[$__key]);
-
}
-
In other words, for each checkbox (you have to specify the name of each checkbox in the array), set $_SESSION['form'][{name of checkbox}] to true if the checkbox was checked or false if not.
For #1, check out the appendix of this article.
well what I am using is this...
[PHP]<?php if( isset($_SESSION['form3']['sunday_desc']) ) echo $_SESSION['form3']['sunday_desc']; ?>[/PHP]
on the form page I do use the <textarea> tags but since I jsut want the data to be echoed onto the final page im just using the value. Now this seems to work half way. By that I mean the final page will display what I typed in on the form but if I go back to the form page everything else re-appears but the textarea will be totaly blank. What am I doing wrong?
so with the checkboxes, is there a way that if checkbox "afghan" is checked on the form, that I could have it just echo "Afghan" on the 4th page as text and thats it?
Thanks again
Heya, Crazy8.
For the textarea, be sure that you're putting the value in between the <textarea> tags instead of using the value attribute:
Do this: -
<textarea name="sunday_desc"><?php if( isset($_SESSION['form3']['sunday_desc']) ) echo $_SESSION['form3']['sunday_desc']; ?></textarea>
-
Instead of this: -
<textarea name="sunday_desc" value="<?php if( isset($_SESSION['form3']['sunday_desc']) ) echo $_SESSION['form3']['sunday_desc']; ?>" />
-
In terms of the checkboxes, you'll have to manually keep track of those: -
if( ! empty($_SESSION['form']['afghan']) )
-
{
-
echo 'Afghan';
-
}
-
Or... -
foreach
-
(
-
array
-
(
-
'afghan' => 'Afghan',
-
'check1' => 'Green',
-
'inputName' => 'Value to display'
-
)
-
as $__key => $__val
-
)
-
{
-
if( ! empty($_SESSION['form'][$__key]) )
-
{
-
echo "{$__val}<br />";
-
}
-
}
-
If I did this...
[PHP]foreach
(
array
(
'afghan' => 'Afghan',
'check1' => 'Green',
'inputName' => 'Value to display'
)
as $__key => $__val
)
{
if( ! empty($_SESSION['form'][$__key]) )
{
echo "{$__val}<br />";
}
}[/PHP]
Then would I still use this code to display it onto the other page?
[PHP]<?php if( isset($_SESSION['form2']['afghan']) ) echo $_SESSION['form2']['afghan']; ?>[/PHP]
The only way I have gotten it to kind of work is doing it this way...
[PHP]foreach(array(
'afghan' => 'Afghan',
'caribbean' => 'Caribbean',
'greek' => 'Greek',
...
...
...
)
as $__key => $__val
)
{
$_SESSION['form2'][$__key] = $__val;
}[/PHP]
But if I do that, then do this onto the page I want the values to display on...
[PHP]<?php if( isset($_SESSION['form2']['afghan']) ) echo $_SESSION['form2']['afghan']; ?>
<?php if( isset($_SESSION['form2']['caribbean']) ) echo $_SESSION['form2']['caribbean']; ?>
<?php if( isset($_SESSION['form2']['greek']) ) echo $_SESSION['form2']['greek']; ?>
...
...
...[/PHP]
then what I get is all of the values displayed onto the page wether the boxes are check or not from the form.
Any ideas on this one? Im getting close (I think)...
Thanks again for all your help.
Heya, Crazy8.
print_r() will be your friend here.
Check some boxes and not others, then on the last page, print_r($_SESSION['form2']). That should give you an idea of what you should be looking for.
Well I have tried the print_r() now and it still isnt working right. I just get all of the checkbox's which get dissplayed something like this...
afghan =>['afghan'] american =>['american'] ...
So am I doing something wrong or did I miss something?
Thank you for all the help with this. These stinken checkboxes are the only thing I have left to get working with this project, then I am done :D
Heya, Crazy8.
Try this: print_r($_POST) after you submit your checkboxes.
Note that only the checkboxes that you actually check will get saved.
This is where it gets tricky, because if the User goes back and *unchecks* a box, you have no way of knowing that!
This is why you have to create an array on the PHP side and explicitly look for each checkbox value to see if it exists in $_POST.
On the last page, remove this code: -
foreach(array(
-
'afghan' => 'Afghan',
-
'caribbean' => 'Caribbean',
-
'greek' => 'Greek',
-
...
-
...
-
...
-
)
-
as $__key => $__val
-
)
-
{
-
$_SESSION['form2'][$__key] = $__val;
-
}
-
All you're doing here is saving values to $_SESSION['form2'] as if the User had checked EVERY checkbox. Oops.
In this case, after the User submits form 2, you'll want to do this: -
foreach(array(
-
'afghan'
-
'caribbean'
-
'greek'
-
.
-
.
-
.)
-
as $__name )
-
{
-
// Was the checkbox checked?
-
if( isset($_POST[$__name]) )
-
{
-
// Yes it was. Add it to $_SESSION.
-
$_SESSION['form2'][$__name] = true;
-
}
-
else
-
{
-
// No it wasn't. Remove it from $_SESSION.
-
$_SESSION['form2'][$__name] = false;
-
}
-
}
-
Then on the last page: -
foreach(array(
-
'afghan' => 'Afghan',
-
'caribbean' => 'Caribbean',
-
'greek' => 'Greek',
-
.
-
.
-
.)
-
as $__key => $__val)
-
{
-
if( $_SESSION[$__key] )
-
{
-
echo "{$__val}<br />";
-
}
-
}
-
If the checkbox was checked (and form 2 saved true for its value in the session), then the text will get output. If the checkbox was not checked (and form 2 saved false for its value in the session), then the text won't get output.
Ok I have done that now but all I get on my last page as far as that goes, is this...
Array ( [afghan] => [caribbean] => [greek] => [korean] => [pizza] => [swedish] => [american] => [chinese] => [indian] => [lebanese] => [peruvian] => [sweets] => [appetizers] => [cuban] => [irish] => [mediterranean] => [portuguese] => [thai] => [brazilian] => [french] => [italian] => [mexican] => [southwestern] => [turkish] => [cajun&creole] => [german] => [japanese] => [middle_eastern] => [spanish] => [vietnamese] => )
any ideas?
thanks
Heya, Crazy8.
Looks like none of the checkbox values got saved.
Which checkboxes did you check to get this result, or does it do this regardless of which checkboxes are checked?
it does it regardless...do I need to do this for each checkbox?
name="food[ ]" I did do it with and without this but still get the same thing.
I still need help with the above question.
Thank you.
Heya, Crazy8.
Let's have a look at the page that processes the checkboxes.
Here is the form with the checkboxes. As you may (or may not) notice, after this page it need to goto step3.php (form 3) then from form 3 onto the 4th page which I want to display ALL the info from the forms...
[PHP]<form method="post" action="step3.php">
<div align="left"><h2><font color="#b80101">Types of Cuisine</font></h2></div>
<fieldset align="center">
<table>
<tr>
<td><input type="checkbox" name="food[]" value="afghan"/></td><td>Afghan</td>
<td><input type="checkbox" name="food[]" value="caribbean"/></td><td>Caribbean</td>
<td><input type="checkbox" name="food[]" value="greek"/></td><td>Greek</td>
<td><input type="checkbox" name="food[]" value="korean"/></td><td>Korean</td>
<td><input type="checkbox" name="food[]" value="pizza"/></td><td>Pizza</td>
<td><input type="checkbox" name="food[]" value="swedish"/></td><td>Swedish</td>
</tr>
<tr>
<td><input type="checkbox" name="food[]" value="american"/></td><td>American</td>
<td><input type="checkbox" name="food[]" value="chinese"/></td><td>Chinese</td>
<td><input type="checkbox" name="food[]" value="indian"/></td><td>Indian</td>
<td><input type="checkbox" name="food[]" value="lebanese"/></td><td>Lebanese</td>
<td><input type="checkbox" name="food[]" value="peruvian"/></td><td>Peruvian</td>
<td><input type="checkbox" name="food[]" value="sweets"/></td><td>Sweets</td>
</tr>
<tr>
<td><input type="checkbox" name="food[]" value="appetizers"/></td><td>Appetizers</td>
<td><input type="checkbox" name="food[]" value="cuban"/></td><td>Cuban</td>
<td><input type="checkbox" name="food[]" value="irish"/></td><td>Irish</td>
<td><input type="checkbox" name="food[]" value="mediterranean"/></td><td>Mediterranean</td>
<td><input type="checkbox" name="food[]" value="portuguese"/></td><td>Portuguese</td>
<td><input type="checkbox" name="food[]" value="thai"/></td><td>Thai</td>
</tr>
<tr>
<td><input type="checkbox" name="food[]" value="brazilian"/></td><td>Brazilian</td>
<td><input type="checkbox" name="food[]" value="french"/></td><td>French</td>
<td><input type="checkbox" name="food[]" value="italian"/></td><td>Italian</td>
<td><input type="checkbox" name="food[]" value="mexican"/></td><td>Mexican</td>
<td><input type="checkbox" name="food[]" value="southwestern"/></td><td>South Western</td>
<td><input type="checkbox" name="food[]" value="turkish"/></td><td>Turkish</td>
</tr>
<tr>
<td><input type="checkbox" name="food[]" value="cajun&creole"/></td><td>Cajun & Creole</td>
<td><input type="checkbox" name="food[]" value="german"/></td><td>German</td>
<td><input type="checkbox" name="food[]" value="japanese"/></td><td>Japanese</td>
<td><input type="checkbox" name="food[]" value="middle_eastern"/></td><td>Middle Eastern</td>
<td><input type="checkbox" name="food[]" value="spanish"/></td><td>Spanish</td>
<td><input type="checkbox" name="food[]" value="vietnamese"/></td><td>Vietnamese</td>
</tr>
</table>
</fieldset>
<a href="step3.php"><img src="img/step3.gif" alt="" border="0"></a>
</form>[/PHP]
and right now I have alot of stuff on "step4" so if you want to see the script in its entirety let me know, as for JUST the code that is relivant to the step2.php stuff, this is what I have right now....
[PHP]<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tbody><tr>
<td width="19%"><b>Types of Cuisine</b><br>
</td>
</tr>
<?php
if ($_SESSION['foods']) {
print "<h2>Selected Foods</h2>";
print "<ul>";
foreach($_SESSION['foods'] as $val) {
print "<li>$val</li>";
}
print "</ul>";
}
?>
</tbody>
</table>[/PHP]
Thank you so much again for your patients and help.
Also incase it matters I am running php5 localy and php4 on a remote server. I have no controll over the remote server.
Any thoughts on this one?
thanks
Heya, Crazy8.
Here's what I would do in this situation. Change the names of your checkboxes to: -
<td><input type="checkbox" name="food[greek]" /></td><td>Greek</td>
-
<td><input type="checkbox" name="food[thai]" /></td><td>Thai</td>
-
<td><input type="checkbox" name="food[martian]" /></td><td>Martian</td>
-
and so on.
When submitting the form, you can then loop through $_POST['food'] and look for keys that have values.
Change your PHP code to this: -
<table border="0" cellpadding="2" cellspacing="0" width="100%">
-
<tbody><tr>
-
<td width="19%"><b>Types of Cuisine</b><br>
-
</td>
-
</tr>
-
-
<?php
-
if ($_SESSION['foods']) {
-
print "<h2>Selected Foods</h2>";
-
print "<ul>";
-
-
foreach($_SESSION['foods'] as $key => $val) {
-
print "<li>$key => $val</li>";
-
}
-
print "</ul>";
-
}
-
?>
-
-
</tbody>
-
</table>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ken |
last post by:
This does not work because of the need for 's.
Is there a way to insert a $_SESSION variable into a database?
Thanks.
mysql_query("INSERT INTO master (id) Values('$_SESSION' ) " ) ;
Ken
|
by: Will Seay |
last post by:
At the end of this message I've pasted a script we're trying to modify
slightly. I don't believe it is VBscript or javascript but these are
the closest groups I could find with my limited...
|
by: Maxime Ducharme |
last post by:
Hi group
We have a problem with sessions in one of our sites.
Sessions are used to store login info & some other infos
(no objects are stored in sessions).
We are using Windows 2000 Server...
|
by: Eugene |
last post by:
I have a table EugeneTest(id_num, fname, minit, lname)
where field "id_num" is type IDENTITY and has UNIQUE constraint
Let's say 2 user execute this code at the same time:
DECLARE @return...
|
by: Rob |
last post by:
I have an ASP.NET application that uses forms-based
authentication. A user wishes to be able to run multiple
sessions of this application simultaneously from the
user's client machine.
The...
|
by: Miguel |
last post by:
Hi all friends:
It's said that Sessions objects in ASP 3.0 with IIS 5.0 occupy certain memory of the machine which take to take care about use a lot of Sessions objects in the ASPs pages of the...
|
by: Daniel Walzenbach |
last post by:
Hi,
I have a web application which sometimes throws an “out of memory”
exception. To get an idea what happens I traced some values using performance
monitor and got the following values (for...
|
by: Atli |
last post by:
Introduction:
Sessions are one of the simplest and more powerful tools in a web developers arsenal. This tool is invaluable in dynamic web page development and it is one of those things every...
|
by: DavidPr |
last post by:
I start sessions on all pages with:ob_start();
session_start(); at the top of the page before anything else.
When I login these sessions are set:$query = "SELECT *
FROM users
WHERE (email='$e'...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
| |