/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] $_post

This is to check if a field is filled out, and for some reason, its not working the way I want it. Do you see any errors?

If something was selected previously, but they didn’t fill out a different field, you will see the page again, but the selection should still be selected, what is happening, is that it isn’t remembering the selected item.

[code=php]echo'<select name=”Gender”>’;
if($_POST[‘gender’] == “Male”){
echo'<option value=”Male” selected>Male</option>’;
}else{
echo'<option value=”Male”>Male</option>’;
}
if($_POST[‘gender’] == “Female”){
echo'<option value=”Female” selected>Female</option>’;
}else{
echo'<option value=”Female”>Female</option>’;
}
echo’
</select>’;[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@firmanJul 22.2006 — maybe you need:

echo'<select name="Gender">';

if($_POST['gender'] == "Male"){

echo'<option value="Male" selected>Male</option>';

}else{

echo'<option value="Male">Male</option>';

}

if($_
POST['gender'] == "Female"){

echo'<option value="Female" selected>Female</option>';

}else{

echo'<option value="Female">Female</option>';

}

echo'

</select>';
Copy linkTweet thisAlerts:
@NogDogJul 22.2006 — Time to echo the value to see if it's being set and is exactly what you're expecting (upper/lower case, exact spelling, spaces, etc.):
[code=php]
echo "<p>DEBUG: value of $_POST['gender'] is '{$_POST['gender']}'</p>n",;
[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyauthorJul 22.2006 — No value is being displayed
Copy linkTweet thisAlerts:
@The_Little_GuyauthorJul 22.2006 — GOT IT!!!

Gender had an uppercase [B]G[/B] and $_POST['gender'] had a lowercase [B]g[/B]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYJul 22.2006 — there you go, when possible try keeping variable names lowercase, that way it's easier to remember (if you make it a convention)
×

Success!

Help @The_Little_Guy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...