Change HTML DropDown Default Value with a MySQL value

Posted by fzr11017 on Stack Overflow See other posts from Stack Overflow or by fzr11017
Published on 2011-11-28T17:38:10Z Indexed on 2011/11/28 17:50 UTC
Read the original article Hit count: 170

Filed under:
|

I'm working on a profile page, where a registered user can update their information. Because the user has already submitted their information, I would like their information from the database to populate my HTML form.

Within PHP, I'm creating the HTML form with the values filled in. However, I've tried creating an IF statement to determine whether an option is selected as the default value. Right now, my website is giving me a default value of the last option, Undeclared. Therefore, I'm not sure if all IF statements are evaluation as true, or if it is simply skipping to selected=selected.

Here is my HTML, which is currently embedded with PHP():

<select name="Major">
            <option if($row[Major] == Accounting){ selected="selected"}>Accounting</option>
            <option if($row[Major] == Business Honors Program){ selected="selected"}>Business Honors Program</option>
            <option if($row[Major] == Engineering Route to Business){ selected="selected"}>Engineering Route to Business</option>
            <option if($row[Major] == Finance){ selected="selected"}>Finance</option>
            <option if($row[Major] == International Business){ selected="selected"}>International Business</option>
            <option if($row[Major] == Management){ selected="selected"}>Management</option>
            <option if($row[Major] == Management Information Systems){ selected="selected"}>Management Information Systems</option>
            <option if($row[Major] == Marketing){ selected="selected"}>Marketing</option>
            <option if($row[Major] == MPA){ selected="selected"}>MPA</option>
            <option if($row[Major] == Supply Chain Management){ selected="selected"}>Supply Chain Management</option>
            <option if($row[Major] == Undeclared){ selected="selected"}>Undeclared</option>
        </select>

© Stack Overflow or respective owner

Related posts about php

Related posts about html-form