SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Autopopulating drop down won't save unless selection is made

    I have a form that autopopulates and allows user to make changes where necessary. In this form are some drop down menus (hardcoded on the page). All the selections (50 states for example) are there. If I select a state it will then post to the database. If I don't select a state and just leave it as the previously selected state (not change the selection already made by a user) it puts a blank in the database.

    Examples:
    The <?="$rest_state_pr"?> will pull the state the user selected previously. If I change the slelection it saves the new selection, but if I leave it as the "default" It puts a blank in the database.

    Drop Down:
    PHP Code:
    <td><select name="rest_state_pr" class="formTextbox" value="<?="$rest_state_pr"?>">
                                            <option value=""><?="$rest_state_pr"?></option>
                                            <option value="Alabama">Alabama</option>
                                            <option value="Alaska">Alaska</option>
                                            <option value="Arizona">Arizona</option>
                                            <option value="Arkansas">Arkansas</option>
                                            <option value="California">California</option>                                                                 
    <option value="Clorado">Colorado</option>
            
    </select></td>
    Form and Query:
    PHP Code:
    <form name="FormName" action="table_order_handler.php" enctype="multipart/form-data" method="post">
                                    
    <?php
    $query
    ="SELECT * FROM abc_tables WHERE table_id=$table_id";
    $result=mysql_query($query);
    while (
    $row mysql_fetch_assoc($result))
    {
    $rest_state_pr $row['rest_state_pr']
    }
    ?>
    Handler:
    PHP Code:
    <?php
    $query_update
    ="UPDATE abc_tables SET rest_state_pr='$rest_state_pr' WHERE table_id='$table_id'";

    mysql_query($query_update) or die(mysql_error());

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    you need to add a selected to the the option and define the option value.
    PHP Code:
    <td><select name="rest_state_pr" class="formTextbox" > 
                   <option value="<?php echo $rest_state_pr?>" selected><?php echo $rest_state_pr?></option>
    // etc
    Select menus themselves DONT have a value either!
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You rock!!

  4. #4
    SitePoint Addict Robert_2006's Avatar
    Join Date
    Jun 2006
    Location
    Tarpon Springs Fl.
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even if you change the value of $rest_state_pr it will still be selected with SpikeZ code.


Bookmarks

Posting Permissions

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