1

I'm having a small problem with one of the drop-down menus in my html form.

On my website, when the user is registering for the first time, he needs to input several attributes. Two of these attributes are populated via selecting from a drop-down menu :

(a) Gender (the drop-down menu holds three values :
SELECT.... MALE FEMALE

(b) Country (the drop-down menu contains a list of ALL countries)

Both these fields are given the "required" property. So, they must always be filled-in.

When the user has filled-in all the date, the form is submitted to the MySQL database.

All A-okay so far.

On my website, there is an option for : "Edit Profile". When the user clicks on this, all his attributes are displayed. And, if he wants to change anything, he is free to do so.

But, here is the problem : the "Gender" field is empty! Which means that : the user is required to re-enter his gender whenever he clicks the "Edit Profile" button (which, of course, is silly!)

Here is the form I use for registration (I'm only displaying these two attributes --- Gender and Country)

    Gender :
    <select name="gender" required>
        <option value="">Select....</option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
    </select>


    Country :
    <select name="country" required>
        <option value="">Country.....</option>
        <option value="Afghanistan">Afghanistan</option>
        <option value="Albania">Albania</option>
        <option value="Algeria">Algeria</option>
        <option value="etc, etc, etc">etc, etc, etc</option>

This form works just fine.

And, here is the form I use for "Edit Profile" :

 Gender : 
 <select name="gender" required>
 <option value="<?=$_SESSION['gender']?>"><?=$_SESSION['gender']?></option>
 <option value="Male">Male</option>
 <option value="Female">Female</option>
 </select>


 Country : 
 <select name="country" required>
<option value="<?=$_SESSION['country']?>"><?=$_SESSION['country']?></option>
 <option value="Afganistan">Afghanistan</option>
 <option value="Albania">Albania</option>
 <option value="Algeria">Algeria</option>
 </select>

Thus : whenever the user opens the "Edit Profile" section, the first value in the drop-down menu is the value which the user ALREADY entered when he registered (extracted from the database). If he wants to change the value, he can then choose from the drop-down.

The "country" attribute works perfectly.

But, the "gender" attribute is empty!

Which is strange, seeing as they are both coded in exactly the same way.

1 Answer 1

1
echo '<pre>'
print_r($_SESSION);

Is it contains gender? :) If your answer is no, try check your php script and queries where you extract these values from db.

Sign up to request clarification or add additional context in comments.

1 Comment

Hahahaha )))))))))))))))))) Silly me. Of course, "gender" is missing from the extract-script DOH !! :=)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.