Confusing Coding Help.

Discussion in 'PHP' started by NuWeb.co.uk, Oct 30, 2005.

  1. #1
    Here is a SNIPPET of my codeing:
    <select name="newcountry" id="newcountry">
    <option <? $val="Afganistan"; echo "value=\"".$val."\""; if ($country == $val) echo "selected"; ?>Afghanistan</option>
    <option <? $val="Albania"; echo "value=\"".$val."\""; if ($country == $val) echo "selected"; ?>Albania</option>
    </select>
    PHP:
    This is the HTML output:
    <select id="newcountry" name="newcountry">
    <option value="Afganistan" selected option Afghanistan<></option>
    <option value="Albania" option Albania<></option>
    </select>
    HTML:
    Get it? .. I dont.. Well confused.

    Point of this code?
    This is going to be a form, which people can select their country, and submit it to a html databse. All that works. The php codeing in the form is theire to set it so, if a user sets their country to UNITED KINGDOM when they go to edit their profile, their country is still UNITED KINGDOM :)
     
    NuWeb.co.uk, Oct 30, 2005 IP
  2. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #2
    Add an extra > after ?> on line 2 and 3 and a space between " and selected.
     
    frankm, Oct 30, 2005 IP
    sarahk likes this.
  3. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #3
    or copy and paste:
    
    <select name="newcountry" id="newcountry">
    <option <? $val="Afganistan"; echo "value=\"".$val."\""; if ($country == $val) echo " selected"; ?>>Afghanistan</option>
    <option <? $val="Albania"; echo "value=\"".$val."\""; if ($country == $val) echo " selected"; ?>>Albania</option>
    </select> 
    
    PHP:
    outputs
    
    <select name="newcountry" id="newcountry">
    <option value="Afganistan" selected>Afghanistan</option>
    <option value="Albania">Albania</option>
    </select>
    
    HTML:
     
    frankm, Oct 30, 2005 IP
  4. NuWeb.co.uk

    NuWeb.co.uk Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    frankm...
    You wont beleave how long ive been trying to sus that out :)
    lol... Thanks allot man.
     
    NuWeb.co.uk, Oct 30, 2005 IP