Newbie: form with a dynamic php drop down.
Posted: Wed Mar 26, 2008 6:21 pm
Well, I could not find a topic/tutorial where they explain what Im trying to. I have a php script pulling data from a DB, and display that in a dropdown menu. Works just fine.
The only thing is, I would like to create a form that shows this php file/dropdown. I can 'include' the php file and it shows the actual drop down. But it also shows an empty dropdown, most likely (I guess) due to the html code.:
But how do you integrate a php file with a form? What I try to do is to show the dropdown, user selects and value gets posted. How does on do that?
I posted the code for the dropdown, cause it might just be part of the problem:
The only thing is, I would like to create a form that shows this php file/dropdown. I can 'include' the php file and it shows the actual drop down. But it also shows an empty dropdown, most likely (I guess) due to the html code.:
Code: Select all
<td>Series in English:
<select id="serie_id" name="series_english">
<?php include('php/DropdownSeries.php'); ?>
</select><br><br><br><br>
</td>
I posted the code for the dropdown, cause it might just be part of the problem:
Code: Select all
<?php
// Open DB
include("library/config.php");
include("library/opendb.php");
// Query the series table and load all of the records
// into an array.
$sql = 'SELECT series_english FROM series';
$res = mysql_query($sql) or die(mysql_error());
while ($rec = mysql_fetch_assoc($res)) $series[] = $rec;
// die('<pre>'.print_r($series));
echo '<SELECT name="dropdown">';
foreach ($series as $c)
{
if ($c['id'] == $_GET['id'])
echo "<OPTION value=\"{$c['id']}\" SELECTED>{$c['series_english']}</OPTION>\n";
else
echo "<OPTION value=\"{$c['id']}\">{$c['series_english']}</OPTION>\n";
}
echo '</SELECT>';
?>