473,786 Members | 2,451 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
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\hsrev ised\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?
Nov 29 '07 #11
pbmods
5,821 Recognized Expert Expert
Heya, Crazy8.

Get rid of the enclosing PHP tags, and you should be good to go.
Nov 29 '07 #12
crazy8
22 New Member
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.
Nov 30 '07 #13
crazy8
22 New Member
Got my issue figured out now. Just need to figure the sql insert stuff.

Thanks again
Nov 30 '07 #14
crazy8
22 New Member
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
Nov 30 '07 #15
pbmods
5,821 Recognized Expert Expert
Heya, Crazy8.

Change the names of your inputs to match the variable names:
Expand|Select|Wrap|Line Numbers
  1. <input name="--> comp_name <--" ... value="<?php if( isset($_SESSION['form']['--> comp_name <--']) ) echo $_SESSION['form']['--> comp_name <--']; ?>" />
  2.  
Nov 30 '07 #16
crazy8
22 New Member
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 "descriptio n" 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
Dec 3 '07 #17
crazy8
22 New Member
Well I think I found my solution to question one. Does anyone have any ideas about question 2 and 3?

Thanks alot
Dec 3 '07 #18
pbmods
5,821 Recognized Expert Expert
Heya, Crazy8.

#2: Textareas handle values a wee bit differently:
Expand|Select|Wrap|Line Numbers
  1. <textarea ...>Value goes inside the tags.</textarea>
  2.  
#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:

Expand|Select|Wrap|Line Numbers
  1. foreach( array('comp_check1', 'names_of', 'checkboxes', 'go_here') as $__key )
  2. {
  3.     $_SESSION['form'][$__key] = isset($_POST[$__key]);
  4. }
  5.  
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.
Dec 4 '07 #19
crazy8
22 New Member
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
Dec 4 '07 #20

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,...
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...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.