I have created a dropdown menu to select the table, then another dropdown menu that is populated with data from from one column of the selected table. Currently, when I first load the page I get an error message as there is nothing selected in my dropdown so the index freqtype
is undefined. When I select something everything works well, except my selection isnt retained by the dropbox. Is there a way within PHP to achieve this within the one script. I thought of maybe using an if statement for the initial form so the bottom dropdown doesnt populate until the top has been selected but I can't get the code to work. Any help would be greatly appreciated.
<html>
<head>
<title>Frequency Chart Update</title>
</head>
<body text="#FFFFFF" bgcolor="#000000">
<font size="4">Please Select the Frequency You Wish To Edit.
</font>
<br>
<br>
<?php
echo '<form ENCTYPE=multipart/form-data action=editfreq.php method=post>';
echo '<select name=freqtype onChange=this.form.submit()>';
echo '<option value="empty"> </option>';
echo '<option value="rptfreq">Repeater (Base) Frequencies</option>';
echo '<option value="pltfreq">Pilot Frequencies (VDV Leaky Feeder)</option>';
echo "</select>";
//define variables to be used
$table = $_POST['freqtype'];
//Connect to database
include 'connect.php';
$sql = "SELECT channel FROM $table";
$result = mysql_query($sql);
echo '<form ENCTYPE=multipart/form-data action=editrptfreq.php method=post>';
echo 'Channel ';
echo '<select name=channel>';
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['channel'] . "'>" . $row['channel'] . "</option>";
}
echo "</select>";
echo "<button type=submit>Select</button>
";
echo "</form>";
?>
</body>
</html>