haseeb
08-18-2012, 01:30 PM
Iam working on a MCQ script in php but having an error while everything looks fine to me.But when i leave the forms blank and submit i get an error.
here is the code
<?php
// Question 1 //
$question1 = $_GET['q1a'];
if($question1=='a')
{
echo "Your answer to question 1 was correct!";
}
if(is_null($question1))
{
echo "You didn't answer question 1.";
}
elseif($question1 != 'a')
{
echo "Your answer to question 1 was incorrect.";
}
// Question 2 //
$question2 = $_GET['q2a'];
if($question2=='a1')
{
echo "Your answer to question 2 was correct!";
}
if(is_null($question2))
{
echo "You didn't answer question 2.";
}
elseif($question2 != 'a1')
{
echo "Your answer to question 2 was incorrect.";
}
?>
<body>
<form method="GET" action="go.php">
1 - Which is the most visited Website in the year 2010 according to a survey?<br>
<input type=radio name='q1a' value='a'>Google<br>
<input type=radio name='q1a' value='b'>Facebook<br>
<input type=radio name='q1a' value='c'>Amazon<br>
<input type=radio name='q1a' value='d'>Yahoo<br>
<br>
<br>
<br>
2 - What does PHP stand for ?<br>
<input type=radio name='q2a' value='a1'> Private Home Page<br>
<input type=radio name='q2a' value='b1'>PHP: Hypertext Preprocessor<br>
<input type=radio name='q2a' value='c1'>Personal Hypertext Processor<br>
<input type=radio name='q2a' value='d1'>Personal Home Page<br>
<input type=submit value='Go'>
</form>
</body>
</html>
And the error i get is this
( ! ) Notice: Undefined index: q1a in C:\webserver\www\test\go.php on line 40
Call Stack
# Time Memory Function Location
1 0.0351 367440 {main}( ) ..\go.php:0
You didn't answer question 1.
( ! ) Notice: Undefined index: q2a in C:\webserver\www\test\go.php on line 56
Call Stack
# Time Memory Function Location
1 0.0351 367440 {main}( ) ..\go.php:0
You didn't answer question 2.
here is the code
<?php
// Question 1 //
$question1 = $_GET['q1a'];
if($question1=='a')
{
echo "Your answer to question 1 was correct!";
}
if(is_null($question1))
{
echo "You didn't answer question 1.";
}
elseif($question1 != 'a')
{
echo "Your answer to question 1 was incorrect.";
}
// Question 2 //
$question2 = $_GET['q2a'];
if($question2=='a1')
{
echo "Your answer to question 2 was correct!";
}
if(is_null($question2))
{
echo "You didn't answer question 2.";
}
elseif($question2 != 'a1')
{
echo "Your answer to question 2 was incorrect.";
}
?>
<body>
<form method="GET" action="go.php">
1 - Which is the most visited Website in the year 2010 according to a survey?<br>
<input type=radio name='q1a' value='a'>Google<br>
<input type=radio name='q1a' value='b'>Facebook<br>
<input type=radio name='q1a' value='c'>Amazon<br>
<input type=radio name='q1a' value='d'>Yahoo<br>
<br>
<br>
<br>
2 - What does PHP stand for ?<br>
<input type=radio name='q2a' value='a1'> Private Home Page<br>
<input type=radio name='q2a' value='b1'>PHP: Hypertext Preprocessor<br>
<input type=radio name='q2a' value='c1'>Personal Hypertext Processor<br>
<input type=radio name='q2a' value='d1'>Personal Home Page<br>
<input type=submit value='Go'>
</form>
</body>
</html>
And the error i get is this
( ! ) Notice: Undefined index: q1a in C:\webserver\www\test\go.php on line 40
Call Stack
# Time Memory Function Location
1 0.0351 367440 {main}( ) ..\go.php:0
You didn't answer question 1.
( ! ) Notice: Undefined index: q2a in C:\webserver\www\test\go.php on line 56
Call Stack
# Time Memory Function Location
1 0.0351 367440 {main}( ) ..\go.php:0
You didn't answer question 2.