Jump to content

populating drop down menu with default values from database


Kay009

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.