I'm having trouble getting a select box to post so that it can be used in an insert sql statement.
my code:
//array of name values for the text input fields
$inputlist = array( "aid" => "Account Number", "name" => "Name", "city" => "City", "state" => "State", "zip" => "Zip",
"email" => "Email", "phone1" => "Phone 1", "phone2" => "Phone 2");
//array for states list
$statelist = array( "AK", "AL", "AR", "AK", "AL", "AR", "AZ", "CA", "CO", "CT", etc...
//my insert statement
//build INSERT QUERY
$query = "INSERT INTO account " .
" ( aid, name, city, state, zip, email, phone1, phone2) " .
"VALUES ('$aid', '$name', '$city', '$state', '$zip', '$email',
'$phone1', '$phone2')";
//and my form
print( "<!-- post form data to addAccount.php -->
<form method = 'post' action = 'addAccount.php'>
<span class = 'prompt'>
Please fill out the fields below.<br /> </span>
<!-- create text boxes for user input -->" );
print("<table>");
foreach ( $inputlist as $inputname => $inputalt )
{
print( "<tr><td><strong>$inputalt</strong></td>");
//states
if ( $inputalt == 'State')
{
print ("<td><select name = 'state'>");
foreach( $statelist as $currstate)
{
print("<option" );
if (( $currstate == $state))
print( " selected = 'true'");
print( ">$currstate</option>");
}
print ("</select></tr>");
}
else
{
print ("<td><input type = 'text'
name = '$inputname' value = '" . $$inputname . "' /></td>" );
if ( $formerrors[ ( $inputname )."error" ] == true )
print( "<td><span class = 'error'>*</span></td>" );
print( "</tr><br />");
}
} // end foreach
print ("</table>");
print("<span class = 'smalltext'>");
print( "<!-- create a submit button -->
<br /><input type = 'submit' name = 'submit'
value = 'Add Account' /></form></body></html>" );
Everything else gets passed to the query just fine but not the selected state. Not sure what I'm doing wrong. Any help would be really appreciated.
Thank you