robert_gsfame Posted August 9, 2009 Share Posted August 9, 2009 i have my edit page called edit.php inside, i have one combobox to edit user country. The problem is that when user has chosen one of several countries listed for example Belgium, he save it and when he is trying to edit several information inside edit.php while ignoring the country information, why does the combobox value automatically change to first index which is Australia?? Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/ Share on other sites More sharing options...
wildteen88 Posted August 9, 2009 Share Posted August 9, 2009 Your combobox wont remember what the user selected unless you tell it to. What is the code you're using to populate the combobox. Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/#findComment-894008 Share on other sites More sharing options...
robert_gsfame Posted August 9, 2009 Author Share Posted August 9, 2009 Opps i have checked it and no value was given....can you help me where should i put the value into Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/#findComment-894010 Share on other sites More sharing options...
wildteen88 Posted August 9, 2009 Share Posted August 9, 2009 Post your code. I cannot suggest what to do if I cant see your code. Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/#findComment-894011 Share on other sites More sharing options...
robert_gsfame Posted August 9, 2009 Author Share Posted August 9, 2009 okay i get the value from my database assume that i've connected to my database and i have this $get = mysql_fetch_array($query); $country = $get['country']; then i have my combobox like this inside edit.php <form method = POST> <select name="country" > <option value="Australia" <?php if (!(strcmp("Australia", ""))) {echo "SELECTED";} ?>>Australia</option> <option value="Belgium" <?php if (!(strcmp(Belgium, ""))) {echo "SELECTED";} ?>>Belgium</option> <option value="Burma" <?php if (!(strcmp(Burma, ""))) {echo "SELECTED";} ?>>Burma</option> <option value="Cambodia" <?php if (!(strcmp(Belgium, ""))) {echo "SELECTED";} ?>>Cambodia</option> </select> </form> then what to do?? Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/#findComment-894017 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Say $countries as an array of all countries and $userCountry is the selected country. <select name="country"> <?php foreach ($countries as $country): ?> <option value="<?php echo $country ?>"<?php if ($country == $userCountry): ?> selected="selected"<?php endif ?>><?php echo $country ?></option> <?php endforeach ?> </select> Or use one block of PHP code and echo statements or whatever you prefer. Link to comment https://forums.phpfreaks.com/topic/169450-combobox-problem/#findComment-894019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.