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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts

    Working with DropDown Menus in PHP

    Hello,

    I made a drop down menu that is dynamically populated with info from my MySQL database. The code is:

    PHP Code:

    <form name="formone" method="post" action="search.php" >
    <p>
    <select id="jump-button">
    <option selected="selected">Choose A Color</option>
    <?php

    // do...while loop to dispay table data
    do {
        
    echo 
    '<option name="colors" value="'.$row['color_one'].'">'.$row['color_one'].'</option>';
          
        
    $row mysql_fetch_assoc($result);    

        } while (
    $row);
    ?>
    </select>

    <input name="send" id="send" type="submit" value="Send message" /> 
        
    </form>
    What I am having trouble figuring out is how to set the input field the user chooses to "selected", then storing the "selected" value in a variable to be used in a later query.

    Any tips?

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you mean that you wish to store which option they select and submit the form? Well, $_POST['colors'] will have the color they selected.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    yes that what I mean but that does not work.

    I did the following code to test it:

    PHP Code:
    if (isset($_POST['send'])) {

        
    $colorSearch $_POST['colors'];
        echo 
    $colorSearch;

    nothing is outputed.
    Last edited by srule_; 11-22-2007 at 03:22 AM.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Move name="colors" into the select tag.

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Posts
    571
    Thanks
    25
    Thanked 28 Times in 28 Posts
    Thanks Inigoesdr,


  •  

    Posting Permissions

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