473,786 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

php sessions and db insert

22 New Member
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_inse rt.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 ">Establish ment Type</td>
<td class="required ">
<select name="comp_type ">
<option selected>- Select One -</option>
<option value="bars">Ba r</option>
<option value="clubs">C lub</option>
<option value="coffee_s hops">Coffee Shop</option>
<option value="resturan ts">Resturant </option>
</select>
</td>
...
<td class="required ">Address</td>
<td class="required "><input type="text" name="comp_addr ess" size="30" maxlength="30" /></td>
...
<td class="required ">Phone Number</td>
<td><input type="text" name="comp_phon e" size="20" maxlength="40" /></td>
...
<td class="required ">Email Address</td>
<td><input type="text" name="comp_emai l" 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 ">Descripti on</td>
<td><textarea name="comp_desc " cols="30" rows="12"></textarea></td>
...
<td class="verdana1 1" 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"><h 2><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>Caribbea n</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="appetizer s"/></td><td>Appetize rs</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="mediterra nean"/></td><td>Mediterr anean</td>
<td><input type="checkbox" id="foods[]" name="portugues e"/></td><td>Portugue se</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>Brazilia n</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="southwest ern"/></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&cre ole"/></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_ea stern"/></td><td>Middle Eastern</td>
<td><input type="checkbox" id="foods[]" name="spanish"/></td><td>Spanish</td>
<td><input type="checkbox" id="foods[]" name="vietnames e"/></td><td>Vietname se</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.
Nov 28 '07
35 3103
crazy8
22 New Member
I still need help with the above question.

Thank you.
Dec 12 '07 #31
pbmods
5,821 Recognized Expert Expert
Heya, Crazy8.

Let's have a look at the page that processes the checkboxes.
Dec 14 '07 #32
crazy8
22 New Member
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.p hp">
<div align="left"><h 2><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="caribbea n"/></td><td>Caribbea n</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="appetize rs"/></td><td>Appetize rs</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="mediterr anean"/></td><td>Mediterr anean</td>
<td><input type="checkbox" name="food[]" value="portugue se"/></td><td>Portugue se</td>
<td><input type="checkbox" name="food[]" value="thai"/></td><td>Thai</td>

</tr>

<tr>
<td><input type="checkbox" name="food[]" value="brazilia n"/></td><td>Brazilia n</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="southwes tern"/></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&cr eole"/></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_e astern"/></td><td>Middle Eastern</td>
<td><input type="checkbox" name="food[]" value="spanish"/></td><td>Spanish</td>
<td><input type="checkbox" name="food[]" value="vietname se"/></td><td>Vietname se</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>Select ed Foods</h2>";
print "<ul>";

foreach($_SESSI ON['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.
Dec 14 '07 #33
crazy8
22 New Member
did that help at all?
Dec 17 '07 #34
crazy8
22 New Member
Any thoughts on this one?

thanks
Dec 19 '07 #35
pbmods
5,821 Recognized Expert Expert
Heya, Crazy8.

Here's what I would do in this situation. Change the names of your checkboxes to:

Expand|Select|Wrap|Line Numbers
  1. <td><input type="checkbox" name="food[greek]" /></td><td>Greek</td>
  2. <td><input type="checkbox" name="food[thai]" /></td><td>Thai</td>
  3. <td><input type="checkbox" name="food[martian]" /></td><td>Martian</td>
  4.  
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:
Expand|Select|Wrap|Line Numbers
  1. <table border="0" cellpadding="2" cellspacing="0" width="100%">
  2. <tbody><tr>
  3. <td width="19%"><b>Types of Cuisine</b><br>
  4. </td>
  5. </tr>
  6.  
  7. <?php
  8. if ($_SESSION['foods']) {
  9.   print "<h2>Selected Foods</h2>";
  10.   print "<ul>";
  11.  
  12.   foreach($_SESSION['foods'] as $key => $val) {
  13.     print "<li>$key => $val</li>";
  14.   }
  15.   print "</ul>";
  16. }
  17. ?>
  18.  
  19. </tbody>
  20. </table>
  21.  
Dec 20 '07 #36

Sign in to post your reply or Sign up for a free account.

Similar topics

11
2050
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
0
6029
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 programming knowledge. Basically, we are trying to add a few lines to this script that will execute a few shell commands (see comments at the very end of the code). We think this may be ActionScript2 but aren't sure. If you can offer any help, or know...
3
2481
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 (IIS 5.0) with ASP 3.0 (no .NET on this site). Sometime, data in session is emptied. I say "sometime"
5
4011
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 integer use EugeneTest INSERT employees ( fname, minit, lname) VALUES
5
673
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 web.config file is configured as such: <authentication mode="Forms"> <forms loginUrl="Login.aspx" protection="All" name="myApplication"/> </authentication>
3
1420
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 applications. So my question is about how recommendable is to use a lot of Sessions objects in ASP.Net I want to use in my application 30 of this objects. Im gonna use them for give permissions to the users of the application. Regards.
6
3807
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 one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
3
28323
Atli
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 developer needs to know how to use. This article explains the basics of PHP Sessions. Assumptions: Basic PHP knowledge is required (variables, arrays and such) HTML Forms. What are Sessions? Sessions are a way of storing data. When developing...
4
1724
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' AND pass=SHA('$p')) AND active IS NULL"; $result = mysql_query ($query); if (@mysql_num_rows($result) == 1) { $row = mysql_fetch_array ($result, MYSQL_NUM);
0
9492
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9960
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.