Form Question

Iam making MCQ script through form but iam stuck with an error. I want the script to make sure/validate if the user has left options blank or haven’t choose any answer but dont know how to do this.Here is my code.
[php]<?php

//Question1//
$question1 = $_GET[‘q1a’];
if ($question1 == ‘a’)
echo “Your First Answer is correct”;

else
echo “Your First Answer is Incorrect”;

echo “
”;

//Question2//
$question2 = $_GET[‘q2a’];

if ($question2 == ‘a1’)

echo “Your Second Answer is Correct”;

else

echo “Your Second Answer is InCorrect”;

?>[/php]

[code]

1 - Which is the most visited Website in the year 2010 according to a survey?
Google
Facebook
Amazon
Yahoo



2 - What does PHP stand for ?
Private Home Page
PHP: Hypertext Preprocessor
Personal Hypertext Processor
Personal Home Page

[/code]

Replace the first text box with this…

[php]<?php

// Question 1 //

$question1=$_GET[‘q1a’];
if($question1=‘a’)
{
echo “Your first answer is correct”;
}
if($question1=’’)
{
echo “You did not enter an answer”;
}
else
{
echo “Your first answer is incorrect”;
}

// Question 2 //

$question2=$_GET[‘q2a’];
if($question2=‘a1’)
{
echo “Your second answer is correct”;
}
if($question2=’’)
{
echo “You did not enter an answer”;
}
else
{
echo “Your second answer is incorrect”;
}

?>[/php]

Oops! Completely discard what I said above… I didn’t read that it was radio options the first time round facepalm

This should work…

[php]<?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.
”;
}

?>[/php]

This is the first time I’ve dealt with nulls that were in checkboxes/radios, so apologies for my amateur-ness. Lol.

Thanks for the help it is working that way and also using the trim function but now i get an error also when leaving both questions blank.
Here is the error.

( ! ) Notice: Undefined index: q1a in C:\webserver\www\test\go.php on line 40 Call Stack # Time Memory Function Location 1 0.0004 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.0004 367440 {main}( ) …\go.php:0

Can you post the whole code for go.php?

Sponsor our Newsletter | Privacy Policy | Terms of Service