Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-23-2010, 06:37 PM   PM User | #1
iaqsuk
New to the CF scene

 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iaqsuk is an unknown quantity at this point
Question 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..
iaqsuk is offline   Reply With Quote
Old 11-25-2010, 04:09 AM   PM User | #2
iaqsuk
New to the CF scene

 
Join Date: Nov 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iaqsuk is an unknown quantity at this point
Anyone?

Has anyone have a clue on my request?
iaqsuk is offline   Reply With Quote
Reply

Bookmarks

Tags
add, country, dropdown, mysql, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:38 AM.


Advertisement
Log in to turn off these ads.