How to update a user selected drop down menu value to database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coder86
    New Member
    • Sep 2010
    • 3

    #1

    How to update a user selected drop down menu value to database

    Hi,

    I am new to this site . I am looking for some help in updating my database from the value selected by user.

    Heres my page I have a table with rows of ID and its status. Status is a drop down menu with 4 possible options. The default displayed is the value from database. When the user picks a value form drop down menu say "completed" I want this value to be updated fro that particular id to database.
    Heres my script to create drop down:
    Code:
    <td WIDTH=200 HEIGHT =40 align="center" rowspan="2">STATUS<form id="main_form" name="main_form" method="post" action="userZFN.php"></td>
    <option value="HOLD" <?php if($row['STATUS']=="HOLD") { echo "selected"; }?>>HOLD</option>
    <option value="ASSIGNED" <?php if($row['STATUS']=="ASSIGNED") { echo "selected"; }?>>ASSIGNED</option>
    <option value="PROGRESS" <?php if($row['STATUS']=="PROGRESS") { echo "selected"; }?>>PROGRESS</option>
    <option value="COMPLETE" <?php if($row['STATUS']=="COMPLETE") { echo "selected"; }?>>COMPLETE</option>
    </select>
    <input type="submit" id="main_submit" name="main_submit" value="submit" />
    </form>
    This drop down is for each row of the status column.

    When The user clicks submit by choosing some status value . I receive it in the same page using post.

    Code:
    }elseif( isset($_POST['main_select'])){	
    $lcSelectedValue = $_POST['main_select'] ;
    echo $lcSelectedValue;
    But when I use update I need to use something like this
    "Update TABLE set COLUMN = 'progress' where ID = $id";


    But How DO I remember the ID???Can I pass the ID through Post/select too???


    Thanks for the help
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Heya coder86! Welcome to Bytes!

    Of course you can!! You can store it on the page in a hidden input field.

    Try that and let us know,


    Dan

    Comment

    • coder86
      New Member
      • Sep 2010
      • 3

      #3
      can you please give me an example ..

      Thanks for replying Dan,

      It would be great if u can give me an example..

      Comment

      • coder86
        New Member
        • Sep 2010
        • 3

        #4
        Thanks Dan,
        I got it to work

        Code:
        	<?php echo "<input type=\"hidden\" id=\"hiddenzid\" name=\"hiddenzid\" value=\"$zid\"/>"; ?>

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          Cool! You're Welcome and thanks for posting the code to help others.

          Dan

          Comment

          Working...