Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Anyone?

    Has anyone have a clue on my request?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •