I have drop downs built by a PHP function pulling from MySQL tables. The drop downs work fine but the selected option isn't POSTing. I suspect the problem is with how the HTML select tag is created in PHP but I can't seem to find a way to correct it. I've searched around but nothing seems to work.
Here is the PHP function to build the drop down:
function contact_list(){
//Connection info
$dbhost = 'localhost';
$db = 'database';
$dbuser = 'user';
$dbpass = 'password';
//Define connection
$con = mysqli_connect($dbhost, $dbuser, $dbpass, $db);
//Check connection
if (mysqli_connect_errno()) {
echo " ERROR " . mysqli_connect_error() . " ERROR ";
}
//Define search strings for drop down
$contact_list = "SELECT * FROM CONTACT_LIST";
//Execute search of primary_contact table
if (!mysqli_query($con,$contact_list)) {
die('' . mysqli_error($con));
}
//Return primary_contact results as string
$contact_result = $con->query($contact_list);
//Build drop down
echo "<select name='Primary_Contact'>";
//Loop through results
foreach ($contact_result as $row)
{
echo "<option value='' >" .htmlspecialchars($row['Primary_Contact']). "</option>";
}
echo "</select><p></p>";
}
Here is a sample of the HTML. The Description text box is fine so I don't think the problem is with the form tags.
<form action="mod_output_test.php" method="POST">
<u>Description</u>: <p></p>
<input type="text" name="Description" size="48" value="<?=$Description;?>"> <p></p>
<!-- Primary Contact -->
<?php echo "<u>Primary Contact</u>:<p></p>Current value: <b> " . $Primary_Contact . "</b>  New value: ";?>
<?php contact_list() ?>
<p></p>
<input type="submit">
</form>
<form>tag, but since you didn't post the HTML, I could be wrong.