Jump to content

Recommended Posts

In this form I need to be able to show the selection already made.  The selection is stored in a mysql db. This form is used to edit the users profile.  How an I show the selections already made?

 

 

 

<div id="profile_info">

      <div id="profile_info_item">
        <label>
          <select name="r_status" id="r_status">
            <option value="1" selected="selected">Single</option>
            <option value="2">Married</option>
            <option value="3">Seperated</option>
            <option value="4">Divorced</option>
            <option value="5">Widowed</option>
            <option value="6">Tell You Later</option>
            </select>
          </label>
        </div>
      
      
  <div id="profile_info_item">
        <select name="race" id="race">
          <option value="1">Caucaisan</option>
          <option value="2">Black</option>
          <option value="3">Hispanic</option>
          <option value="4">Asain</option>
          <option value="5">Indian</option>
          <option value="6">European</option>
          <option value="7">Middle Eastern</option>
          <option value="8">Mixed Black / White</option>
          <option value="9">Native American</option>
          <option value="10">Other Ethnicity</option>
        </select>
      </div>
  <div id="profile_info_item">
        <select name="age" id="age">
          <option value="1" selected="selected">18-21</option>
          <option value="2">21-23</option>
          <option value="3">23-25</option>
          <option value="4">25-27</option>
          <option value="5">27-29</option>
          <option value="6">29-31</option>
          <option value="7">31-33</option>
          <option value="8">33-35</option>
          <option value="9">35-37</option>
          <option value="10">37-39</option>
          <option value="11">39-41</option>
          <option value="12">41-43</option>
          <option value="13">43-45</option>
          <option value="14">45-47</option>
          <option value="15">47-49</option>
          <option value="16">49-51</option>
          <option value="17">51-53</option>
          <option value="18">53-55</option>
          <option value="19">55-57</option>
          <option value="20">57-59</option>
          <option value="21">59-61</option>
          <option value="22">61-63</option>
          <option value="23">63-65</option>
          <option value="24">65-67</option>
          <option value="25">67-69</option>
          <option value="26">69-71</option>
          <option value="27">71-73</option>
          <option value="28">73-75</option>
          <option value="29">75-77</option>
          <option value="30">77-79</option>
          <option value="31">79-81</option>
          <option value="32">81-83</option>
          <option value="33">83-85</option>
          <option value="34">85-87</option>
          <option value="35">87-89</option>
          <option value="36">89-91</option>
          <option value="37">91-93</option>
          <option value="38">93-95</option>
          <option value="39">95-97</option>
          <option value="40">97-99</option>
          <option value="41">99-101</option>
          <option value="42">101-103</option>
        </select>
      </div>


  <div id="profile_info_item">
        <select name="orie" id="orie">
          <option value="1">Straight</option>
          <option value="2">Bi-Curious</option>
          <option value="3">Bi-Sexual</option>
          <option value="4">Gay</option>
          <option value="5">Lesbian</option>
        </select>
      </div>
  <div id="profile_info_item">        
  <select name="orie" id="orie">
    <option value="1">Male</option>
    <option value="2">Female</option>
    <option value="3">TS/TG/TV</option>
  </select>
        
       </div>

  <div id="profile_info_item">
        <select name="body" id="body">
          <option value="1">Thin</option>
          <option value="2">Athletic</option>
          <option value="3">Average</option>
          <option value="4">BBW</option>
          <option value="5">A Few Extra Pounds</option>
          <option value="6">Muscular</option>
          <option value="7">Curvy</option>
          <option value="8">Show You Later</option>
        </select>
      </div>
  <div id="profile_info_item">
        <select name="height" id="height">
          <option value="1">less than 5ft</option>
          <option value="2">5ft 1in</option>
          <option value="3">5ft 2in</option>
          <option value="4">5ft 3in</option>
          <option value="5">5ft 4in</option>
          <option value="6">5ft 5in</option>
          <option value="7">5ft 6in</option>
          <option value="8">5ft 7in</option>
          <option value="9">5ft 8in</option>
          <option value="10">5ft 9in</option>
          <option value="11">5ft 10in</option>
          <option value="12">5ft 11in</option>
          <option value="13">6ft</option>
          <option value="14">6ft 1in</option>
          <option value="15">6ft 2in</option>
          <option value="16">6ft 3in</option>
          <option value="17">6ft 4in</option>
          <option value="18">6ft 5in</option>
          <option value="19">6ft 6in</option>
          <option value="20">6ft 7in</option>
          <option value="21">6ft 8in</option>
          <option value="22">6ft 9in</option>
          <option value="23">6ft 10in</option>
          <option value="24">6ft 11in</option>
          <option value="25">7ft</option>
          <option value="26">7ft+</option>
        </select>
      </div>
  <div id="profile_info_item">
        <select name="hair" id="hair">
          <option value="1" selected="selected">Black</option>
          <option value="2">Brown</option>
          <option value="3">Blonde</option>
          <option value="4">Red</option>
          <option value="5">Gray</option>
          <option value="6">Bald</option>
          <option value="7">Mixture of Colors</option>
          </select>
        </div>
  <div id="profile_info_item">
        <select name="eyes" id="eyes">
          <option value="1">Brown</option>
          <option value="2">Blue</option>
          <option value="3">Green</option>
          <option value="4">Light Brown</option>
          <option value="5">Hazel</option>
        </select>
        </div>
        
  <div id="profile_info_item">
<input type="submit" name="submit" id="submit" value="Save Changes" />
        </div>
        
      </div>

Link to comment
https://forums.phpfreaks.com/topic/266637-php-form-help/
Share on other sites

Something like this:

// this variable would come from the result set of a query
// but the value is set for the sake of brevity
$r_status = 3;

.....

<div id="profile_info_item">
  <label>
    <select name="r_status" id="r_status">
  <option value="1"<?php echo $r_status == 1 ? ' selected="selected"' : ''; ?>>Single</option>
  <option value="2"<?php echo $r_status == 2 ? ' selected="selected"' : ''; ?>>Married</option>
  <option value="3"<?php echo $r_status == 3 ? ' selected="selected"' : ''; ?>>Seperated</option>
  <option value="4"<?php echo $r_status == 4 ? ' selected="selected"' : ''; ?>>Divorced</option>
  <option value="5"<?php echo $r_status == 5 ? ' selected="selected"' : ''; ?>>Widowed</option>
  <option value="6"<?php echo $r_status == 6 ? ' selected="selected"' : ''; ?>>Tell You Later</option>
</select>
  </label>
</div>

 

If you put your options in an array you can reduce the amount of code duplication, but this will work fine too.

 

Also, you are using the same ID for multiple elements. ID's are supposed to be unique; you can only use them on one element. You need to use classes instead, which can be used on multiple elements.

Link to comment
https://forums.phpfreaks.com/topic/266637-php-form-help/#findComment-1366561
Share on other sites

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.