Kay009 Posted November 8, 2009 Share Posted November 8, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/180755-populating-drop-down-menu-with-default-values-from-database/ Share on other sites More sharing options...
ashton321 Posted November 8, 2009 Share Posted November 8, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/180755-populating-drop-down-menu-with-default-values-from-database/#findComment-953754 Share on other sites More sharing options...
Kay009 Posted November 8, 2009 Author Share Posted November 8, 2009 thanks ,let me try this out=] Quote Link to comment https://forums.phpfreaks.com/topic/180755-populating-drop-down-menu-with-default-values-from-database/#findComment-953790 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.