I have a dropdown box on my form which is populated from a MySQL database. When a value is selected i want to open a larger form and set the value selected initially to become the selected value on the new form.
My HTML code for the Combo is as follows
<select id ="Opponents" name ="Opponents"
<?php
opponent_load(Wheathill)
?>
>
</select>
The PHP function, which is used to populate the dropdown list as well as set the SELECTED value to display, is as follows ;
function opponent_load($oppt){
$db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS );
$database = "matchmanagementdb";
$db_found = mysqli_select_db($db_handle, $database);
if ($db_found) {
$SQL = "SELECT * FROM opponentsdb";
$result = mysqli_query($db_handle, $SQL);
while ( $db_field = mysqli_fetch_assoc($result) ) {
$uName = $db_field['Opponents'];
if ($uName == $oppt) {
$selected = 'selected="selected"';
} else {
$selected = '';
}
echo "<option value='$uName' '$selected'> $uName </option>";
}
} else {
print "Database NOT Found ";
}
mysqli_close($db_handle);
}
The new form has the values in the dropdown box BUT the selected value is not shown as Wheathill. I intend to replace the function argument "Wheathill" with a variable that will be defined in another function. Can anyone help as to why the code does note work.
The code above is part of a larger code which includes a reference to the values required by the mysqli_connect() function
NOTE Novice at PHP.