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"> </td>
<td width="249"> </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> </td>
<td> </td>
</tr>
<tr>
<td class="style1">How many drivers are in your household? </td>
<td> </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> <span class="style6"> * Include yourself, your spouse, anyone of driving age in your household, and all other drivers of your vehicles.</span> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="style1">How many vehicles are you insuring? </td>
<td> </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> </td>
<td> </td>
<td> </td>
</tr>
</table>
<table width="682" border="0" align="center" cellpadding="0" id="step_two">
<tr>
<td width="39"> </td>
<td width="228"> </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> </p>
</body>
</html>[/PHP]