Hi everyone. My first post here. I am a beginner and have created a contact form. Unfortunately, My “province_state” variable value does not retain the selection. I would really appreciate some help in solving this.
Here is the link to my php file.
http://barrytowns.com/php/lesson_four_customer_data.php
And here is the code to my include file. I have commented on line 133 that /* THIS IS WHERE MY PROBLEM IS */ to indicate the following block of echo commands. I know I am getting something in the wrong place or order but trial and error has not given me the solution. Thanks to anyone who can lend me a hand…
<?php /* Program name: lesson_four_customer_data.inc * Description: Defines a form that collects customer data for shipping and marketing purposes. */ $labels = array( "last_name" => "Last Name", "first_name" => "First Name", "street_address" => "Street Address", "city" => "City", "province_state" => "Province or State", "country" => "Country", "postal_zip_code" => "Postal code or Zip", "phone_number" => "Phone number", "email" => "Email"); $province_state = array ( "UNITED_STATES"=>"US", "Alabama" => "AL", "Alaska" => "AK", "Arizona" => "AZ", "Arkansas" =>"AR", "California" =>"CA", "Colorado" =>"CO", "Connecticut" =>"CT", "Delaware" =>"DE", "District_of_Columbia" =>"DC", "Florida" => "FL", "Georgia" =>"GA", "Hawaii" =>"HI", "Idaho" => "ID", "Illinois" =>"IL", "Indiana"=>"IN", "Iowa" => "IA", "Kansas" =>"KS", "Kentucky" =>"KY", "Louisiana" =>"LA", "Maine" =>"ME", "Maryland" =>"MD", "Massachusetts" =>"MA", "Michigan" =>"MI", "Minnesota" =>"MN", "Mississippi" =>"MS", "Missouri" =>"MO", "Montana" =>"MT", "Nebraska" =>"NE", "Nevada" =>"NV", "New_Hampshire" =>"NH", "New_Jersey" =>"NJ", "New_Mexico" =>"NM", "New_York" =>"NY", "North_Carolina" =>"NC", "North_Dakota" =>"ND", "Ohio" =>"OH", "Oklahoma" =>"OK", "Oregon" =>"OR", "Pennsylvania" =>"PA", "Rhode_Island" =>"RI", "South_Carolina" =>"SC", "South_Dakota" =>"SD", "Tennessee" =>"TN", "Texas" =>"TX", "Utah" =>"UT", "Vermont" =>"VT", "Virginia" =>"VA", "Washington" =>"WA", "West_Virginia" =>"WV", "Wisconsin" =>"WI", "Wyoming" =>"WY", "CANADA"=>"Cd", "Alberta" =>"AB", "British Columbia" =>"BC", "Manitoba" => "MB", "New Brunswick" => "NB", "Newfoundland" =>"NF", "Northwest Territories" =>"NT", "Nova Scotia" => "NS", "Nunavut" =>"NU", "Ontario" => "ON", "Prince Edward Island" =>"PE", "Quebec" =>"QC", "Saskatchewan" => "SK", "Yukon Territory" => "YT"); $submit = "SUBMIT"; ?> <!-- form {
margin: 1.5em 0 0 0;
padding: 0;
}
.field {padding-bottom: 1em;}
label {
font-weight: bold;
float: left;
width: 20%;
margin-right: 1em;
text-align: right;
}
.submit {
margin-left: 35%;
}
h3 {
font-family: arial;
text-align: center;
}
label {
font-family: arial;
font-size: 14px;
}
–>
Please fill out the form below to register with
SWAMPLAND PHOTOGRAPHY
<?php /* THIS IS WHERE MY PROBLEM IS */echo "<form action='$_SERVER[PHP_SELF]' method='POST'>";
foreach($labels as $field => $label)
if($field == "province_state")
{
echo “
$label”;
echo"";
foreach($province_state as $value => $province_state_abr)
{
}
";
?>
echo"";
foreach($province_state as $value => $province_state_abr)
{
echo"<option value='$province_state_abr'>";
if($_POST['province_state'] == $province_state_abr)
{
echo " selected='selected'";
}">";
echo"$province_state_abr";
echo"</option>";
}
echo"</select>";
echo"</div>";
}
else
{
echo "
$label
";}
echo “”;
echo "
?>