Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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