View Full Version : php mysql dropdown lists help

11-23-2010, 06:37 PM
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">
<td colspan="2">Countries</td>
<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>";
<td>Add Country if not listed</td>
<td><input type="text" name="country" size="25"></td>
<td><input type=submit name=submit value="Add Country"></td>

I would appreciate all the help. Thank you.

11-25-2010, 04:09 AM
Has anyone have a clue on my request?