•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,999 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,533 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 234 | Replies: 1 | Solved
![]() |
•
•
Join Date: Apr 2006
Posts: 62
Reputation:
Rep Power: 3
Solved Threads: 0
Hi,
This code works fine but, when i choose "Female" from selectbox, it sets "Male" in the selectbox again. What is the problem?
Thanks
This code works fine but, when i choose "Female" from selectbox, it sets "Male" in the selectbox again. What is the problem?
Thanks
<?php
if (!isset($_POST["sex"])) {
print "Please start!";
} else if ("Male" == $_POST["sex"]) {
print "Male !";
} else if ("Female" == $_POST["sex"]) {
print "Female !";
} else {
print "Himmm!";
}
?>
<html>
<head></head>
<body>
<form action="result.php" method="post">
SEX? <select name="sex" >
<option value="Male">Male</option>
<option value="Female">Female</option>
</select><br>
<input type="submit" value="Send">
</form>
</body>
</html>•
•
Join Date: Oct 2007
Posts: 24
Reputation:
Rep Power: 1
Solved Threads: 0
There is much cleaner ways to do this but for a quick fix, below should now work as you expect:
<?php
if (!isset($_POST["sex"])) {
print "Please start!";
} else if ("Male" == $_POST["sex"]) {
print "Male !";
$male_checked = " SELECTED";
} else if ("Female" == $_POST["sex"]) {
print "Female !";
$female_checked = " SELECTED";
} else {
print "Himmm!";
}
?>
<html>
<head></head>
<body>
<form action="result.php" method="post">
SEX? <select name="sex" >
<option value="Male" <?php echo $male_checked ?>>Male</option>
<option value="Female" <?php echo $female_checked ?>>Female</option>
</select><br>
<input type="submit" value="Send">
</form>
</body>
</html> ![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the PHP Forum
- Previous Thread: T_string error message
- Next Thread: how to save and retrieve an image using mysql and php


Linear Mode