php mysql dropdown lists help
I've asked this question a few years ago but lost the script, so I know it can be done.
(Protected page)
I have a contact form or add page form, using this example:
existing dropdown list (countries)
I need next to the existing dropdown list, text input box, then a add button (add your country if not listed)
then it shows in existing dropdown list after refreshing the page.
I know that from the years ago post, javascript needs to be involved once you add a new country. Below is an example code:
<?
// connect to database
$connection = mysql_connect($host, $username, $password) or die ("Unable to connect!");
?>
<table border="0" cellspacing="0" cellpadding="0" colspan="2">
<form action="<? echo $PHP_SELF; ?>" method="POST">
<tr>
<td colspan="2">Countries</td>
<tr>
<td><select name="country">
<?
// get country list
$query = "SELECT id, country from countries";
$result = mysql_db_query($database, $query, $connection) or die ("Error in query: $query. " . mysql_error());
while (list($id, $country) = mysql_fetch_row($result))
{
echo "<option value=$id>$country</option>";
}
mysql_free_result($result);
?>
</select></td>
<td>Add Country if not listed</td>
<tr>
<td><input type="text" name="country" size="25"></td>
<td><input type=submit name=submit value="Add Country"></td>
</form></table>
I would appreciate all the help. Thank you.
Last edited by iaqsuk; 11-23-2010 at 06:44 PM..
|