Jump to content

combobox problem


robert_gsfame

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.