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
Simple Radio Button Problem
Moderator: General Moderators
Re: Simple Radio Button Problem
echo "You are correct. $_POST['selection1'] is the right answer.";
within double quotes, PHP will only eval $var. Concat with '.' so:
echo "You are correct. ".$_POST['selection1']." is the right answer.";
I would advise string quote char for faster parsing...
echo 'You are correct. '.$_POST['selection1'].' is the right answer.';
hope that helps...
within double quotes, PHP will only eval $var. Concat with '.' so:
echo "You are correct. ".$_POST['selection1']." is the right answer.";
I would advise string quote char for faster parsing...
echo 'You are correct. '.$_POST['selection1'].' is the right answer.';
hope that helps...
-
willactnow
- Forum Newbie
- Posts: 2
- Joined: Thu Sep 17, 2009 10:13 am
Re: Simple Radio Button Problem
Thanks for the help.