473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Saving form values between page loads

I'm teaching myself PHP with limited success. I'm using PHP5 and dreamweaver.

I have a basic drop down menu on a form.

If the user forgets to enter some data I send him back to the form. What I need help with is how to show what was selected the first time so that he doesn't have to reenter all data just the missing stuff.

I'm really new at this and could use some direction.

Thanks

Here's the code

[PHP]<?php session_start();
$number_drivers = '';
$number_vehicles = '';
$error = array();
// read somewhere to set session variables to nothing at beginning
$_SESSION['number_drivers'] = $number_drivers;
$_SESSION['number_vehicles'] = $number_vehicles;

if (array_key_exists('step_two', $_POST)) {
// continue to step two button clicked
// get input and check for errors

if (empty($_POST['number_drivers'])) {
$error['number_drivers'] = 'Please enter the number of drivers';
}
if (empty($_POST['number_vehicles'])) {
$error['number_vehicles'] = 'Please enter the number of vehicles';
}

if (!$error) {
// store input to session variables

$_SESSION['number_drivers'] = $_POST['number_drivers'];
$_SESSION['number_vehicles'] = $_POST['number_vehicles'];

// go to step two
session_write_close();
header('Location: http://localhost/btracy_auto_quotes_2.php');
exit;
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<link href="CssFiles/tracy.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#auto1_main {position:absolute;
width:713px;
height:399px;
z-index:1;
left: 175px;
top: 20px;
}
.style6 {font-size: 12px}
.left_info {font-size: small}
.style1 {font-size: 14px}

.style7 {font-size: x-small}
-->
</style>
</head>

<body>
<div id="auto1_main">
<table width="700" border="0" align="center" cellpadding="0">
<tr>
<td><form id="auto_one" name="auto_one" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<table width="680" border="0" align="center" cellpadding="0">
<tr>
<td colspan="3"><div align="center">
<h3>Auto Quote Step 1 of 2</h3>
</div>
</td>
</tr>
<tr>
<td width="402"><h3>About You </h3></td>
<td width="21">&nbsp;</td>
<td width="249">&nbsp;</td>
</tr>
<tr>
<td height="15"><?php if (isset($error['number_drivers'])) { ?>
<span class="warning"><?php echo $error['number_drivers']; ?></span><br />
<?php } ?>

<?php if (isset($error['number_vehicles'])) { ?>
<span class="warning"><?php echo $error['number_vehicles']; ?></span><br />
<?php } ?>

</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1">How many drivers are in your household? </td>
<td>&nbsp;</td>
<td>
<select name="number_drivers" id="number_drivers">
<option value="" selected="selected">Please Select</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
<span class="left_info">*</span> </td>
</tr>
<tr>
<td>&nbsp;<span class="style6">&nbsp; * Include yourself, your spouse, anyone of driving age in your household, and all other drivers of your vehicles.</span> </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td class="style1">How many vehicles are you insuring? </td>
<td>&nbsp;</td>
<td><select name="number_vehicles" id="number_vehicles">
<option value="" selected="selected">Please Select</option>
<option value="9">Zero</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
</select>
<span class="left_info"> *</span>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<table width="682" border="0" align="center" cellpadding="0" id="step_two">
<tr>
<td width="39">&nbsp;</td>
<td width="228">&nbsp;</td>
<td width="407"><input name="step_two" type="submit" id="step_two" value="Continue to Step Two" /></td>
</tr>

</table>
</form>

</td>
</tr>
</table>
</div>
<p>&nbsp;</p>

</body>
</html>[/PHP]
Jul 31 '07 #1
2 1462
code green
1,726 Expert 1GB
The technique you are looking for is known as sticky forms.
I am not going to attempt to show you because the syntax is tricky.
But it is simple to understand.
Larry Ullman explains it well. Try this link
http://www.peachpit.com/articles/art...&seqNum=3&rl=1
Jul 31 '07 #2
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem.
Jul 31 '07 #3

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

Similar topics

0
by: William Morris | last post by:
We have a number of clients using a web application. Each client sees a slightly different version of, say, a contact input page. As a simple example, Client #1 sees demographics, plus religious...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
0
by: headware | last post by:
I've been reading about saving the state of the controls of a page so the user can be redirected to another page and then return to the original in the state it was in when they left. I've seen a...
3
by: Mats Boberg | last post by:
Hi, I have problems with saving a bitmap to hdd from my asp.net page I get the following error: "A generic error occurred in GDI+." Code: Bitmap bmp = new Bitmap(240,120);
6
by: Sean | last post by:
HI There, I am making the transition from asp to asp .net, I am currenty writing an application that requires a bulk insert from a webform into SQL server, normally I would just create rows of...
2
by: Paul K | last post by:
I have the user selecting a record on one page of the web app I'm working on. After they select a record, I save the record into a session variable and submit the main page (in another window). In...
4
by: pbd22 | last post by:
hi. could somebody tell me, when uploading a file, i know the form where the upload component is must have enctype=multipart/form-data but, is the same true for the form with the server code to...
5
by: jmartmem | last post by:
Greetings, I have built an Update Record Form in an ASP page. This form contains a number of fields, such as text boxes and menus, to name a few. Upon clicking the 'submit' button, I want the...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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,...
0
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...
0
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 project—planning, coding, testing,...

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.