Simple Radio Button Problem
Posted: Wed Sep 30, 2009 3:06 am
Hi
I am new to php. As I am trying to write simple code I got a problem with the output. I just want to give user a option to select a option from the list and when the user press submit the program should display the result that entry is correct or not. The capital of Punjab is Chandigarh.The code is :
<HTML>
<HEAD><TITLE>Quiz</TITLE></HEAD>
<BODY>
<?php
If(isset($_POST[posted]))
{
if($_POST[selection1]=="Chandigarh"){
echo "You are correct. $_POST[selection1] is the right answer.";}
if($_POST[selection1]!="Chandigarh"){
echo "You are incorrect. $_POST[selection1] is not the right answer.";}
}
?>
<form method="POST" action="quiz.php">
<input type="hidden" name="posted" value="true">
What is the capital of Punjab?
<BR>
<input type="radio" name="selection1" value="Chandigarh">Chandigarh <BR>
<input type="radio" name="selection1" value="Panchkula">Panchkula<BR>
<input type="radio" name="selection1" value="Jalandhar">Jalandhar<BR>
<input type="submit" value="Submit">
</form>
<BODY>
</HTML>
The name of the city is not coming incase he user select something other than Chandigarh. But its ok when the user selects Chandigarh. The output says :
You are correct. Chandigarh is the right answer.
Why cityname is not coming incase user selects some other option. The output comes only like:
You are incorrect. is not the right answer.
Kindly help
I am new to php. As I am trying to write simple code I got a problem with the output. I just want to give user a option to select a option from the list and when the user press submit the program should display the result that entry is correct or not. The capital of Punjab is Chandigarh.The code is :
<HTML>
<HEAD><TITLE>Quiz</TITLE></HEAD>
<BODY>
<?php
If(isset($_POST[posted]))
{
if($_POST[selection1]=="Chandigarh"){
echo "You are correct. $_POST[selection1] is the right answer.";}
if($_POST[selection1]!="Chandigarh"){
echo "You are incorrect. $_POST[selection1] is not the right answer.";}
}
?>
<form method="POST" action="quiz.php">
<input type="hidden" name="posted" value="true">
What is the capital of Punjab?
<BR>
<input type="radio" name="selection1" value="Chandigarh">Chandigarh <BR>
<input type="radio" name="selection1" value="Panchkula">Panchkula<BR>
<input type="radio" name="selection1" value="Jalandhar">Jalandhar<BR>
<input type="submit" value="Submit">
</form>
<BODY>
</HTML>
The name of the city is not coming incase he user select something other than Chandigarh. But its ok when the user selects Chandigarh. The output says :
You are correct. Chandigarh is the right answer.
Why cityname is not coming incase user selects some other option. The output comes only like:
You are incorrect. is not the right answer.
Kindly help