Jump to content

populating drop down menu with default values from database


Recommended Posts

i have to make a edit information form for users.Instread of making users reenter the information,it must be populated with default values where users may just change the spelling mistakes they have had made to the data they have previously entered.

 

i have figured out for input textbox but how to retrieve user data for drop down menu?

................

$userfinal=$username;

if(isset($userfinal)){

 

//query for gettng user details from the table UserAccount

$query="SELECT * FROM UserAccount WHERE UserName='$userfinal'";

$result=mysql_query($query);

$user=mysql_fetch_assoc($result);

 

$gender1=$user['Gender'];

$phone1=$user['PhoneNumber'];

$country1=$user['Country'];

$zipcode1=$user['ZipCode'];

 

 

 

    <td ><h2>Edit Details</h2>

      <p class="one">All the fields with an asterisk(*) are mandatory and cannot be left blank.</p>

   

   

    <!-- Form-->

    <form id="EditUser" name="EditUser" action="editdetail.php" method="post">

     

      <fieldset>

        <legend>Change Personal Information</legend>

        <p>Please re-enter your personal information you want to change.</p>

        <table class="two">

          <tr>

            <td>First Name :</td>

            <td><input type="text" id="FirstName"  name="FirstName" tabindex="4" maxlength="25"      value="<?php echo $fname ?>"/>

            *</td>

          </tr>

          <tr>

            <td>Last Name :</td>

            <td><input type="text" id="LastName"  name="LastName" tabindex="5"  maxlength="25" value="<?php echo $lname ?>"/>

            *</td>

          </tr>

          <tr>

            <td>Gender : </td>

            <td><select  tabindex="8" id="Gender" name="Gender">

              <option value="Male">Male</option>

              <option value="Female">Female</option>

              <option value="Undisclosed">Undisclosed</option>

              </select></td>

          </tr>

 

There may be a better way, but this is how i do it.

 

<td><select  tabindex="8" id="Gender" name="Gender">
              <option value="Male" <?php if($gender1 == 'Male'){echo 'selected';} ?>>Male</option>
              <option value="Female" <?php if($gender1 == 'Female'){echo 'selected';} ?>>Female</option>
              <option value="Undisclosed" <?php if($gender1 == 'Undisclosed'){echo 'selected';} ?>>Undisclosed</option>
              </select></td>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.