Still stuck on this one guys.
Here's my select menu so far...
// get locations
$query = "SELECT * ".
"FROM location";
$result = mysql_query($query) or die(mysql_error());
// process location results
echo '<p>';
if(isset($error_message['location'])) { echo $error_message['location'].'<br />'; }
echo '<label for="location">Location: <span class="star">*</span></label><select name="location">';
// if location already selected
if(isset($location) && ($location != "0"))
{
echo '<option value="'. $location .'" selected>'.$_POST['location_name'].'</option>';
}
else
{
echo '<option value= "0">Select Location</option>';
}
while($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['location_ID'].'">'.$row['location_name'].'</option>';
}
echo '</select></p>';
So if the form is submitted and the location field should contain the selected value. (so if form error the user won't have to select location again.)
However, when a location is selected and the form is submitted, the first selection is then set as blank. In view source the code is <option value="1" selected>
So I'm thinking that it's not getting the $location or $_POST['location'] variable??
The form values are submitted to the same page. i.e. the processing code is at the top of the page before the DOCTYPE.
So $location = $_POST['location']; is declared at the top.
Here is the top...Is it correct to place at page beginning??
<?php
session_start();
/***********************
declare variables
***********************/
$submit = $_POST['submit'];
$location = $_POST['location'];
// time start
$hr_start = $_POST['hour'];
// declare an empty error array
$error_message = array();
// if form submitted
if(isset($submit))
{
/*************************
Form Error Checking
*************************/
if(!$location || $location == "0")
{
$error_message['location'] = 'Please Select a Location';
}
/*************************
End Form Checking
*************************/
/*********************************
If No Form Errors
*********************************/
if(count($error_message) == 0)
{
// declare an empty error array
$db_message = array();
// connect to db
include('../db_connect.php');
/*********************************
if no error messages
*********************************/
if((count($error_message) == 0) && (count($db_message) == 0))
{
// insert into db
$query = "INSERT INTO meeting ".
"VALUES(NULL, '$location', '$time_start')";
$final_result = mysql_query($query) or die(mysql_error());
// if query successful
if($final_result)
{
// declare an empty error array
$result_message = array();
$result_message['result'] = '<p>Meeting Successfully Registered.</p>';
}
}
} // end count
}// end isset $submit
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">