missingcolor123 Posted November 13, 2011 Share Posted November 13, 2011 Hi, I am trying to create a drop down menu that will select a value that is stored in the database - right now the code creats a dropdown (with nothing selected) - hope someone can help. in the database, the values are stored as --null- Option1 Option2 Option3 my code is $instruction = $_GET['instruction']; <?php <select id="instruction" name="instruction"> <option value="" <?php if (!empty($instruction) && $instruction == '' ) echo 'selected = "selected"'; ?>></option> <option value="Option1" <?php if (!empty($instruction) && $instruction == 'Option1') echo 'selected = "selected"'; ?>>Option1</option> <option value="Option2" <?php if (!empty($instruction) && $instruction == 'Option2') echo 'selected = "selected"'; ?>>Option2</option> <option value="Option3" <?php if (!empty($instruction) && $instruction == 'Option3') echo 'selected = "selected"'; ?>>Option3</option> </select> <? Link to comment https://forums.phpfreaks.com/topic/251071-drop-down-select-option-based-on-stored-value/ Share on other sites More sharing options...
sunfighter Posted November 13, 2011 Share Posted November 13, 2011 if (!empty($instruction) && $instruction == '' ) That ain't gonna work!!! It's empty [ $instruction == '' ] and it's not empty [ !empty($instruction) ] Link to comment https://forums.phpfreaks.com/topic/251071-drop-down-select-option-based-on-stored-value/#findComment-1287892 Share on other sites More sharing options...
missingcolor123 Posted November 14, 2011 Author Share Posted November 14, 2011 thanks, i rewrote it without doing the if empty check and it worked <option value="Option1" <?php if ($row1['instruction'] == 'Option1') echo 'selected = "selected"'; ?>>Option1</option> thanks for your help Link to comment https://forums.phpfreaks.com/topic/251071-drop-down-select-option-based-on-stored-value/#findComment-1287918 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.