Gossamer Forum
Home : General : Internet Technologies :

$HTTP_POST_VARS - multiple answers

Quote Reply
$HTTP_POST_VARS - multiple answers
I hope I am posting at the right forum.

I am a newbie to PHP. I have developed a quiz. It's working great except I am having problems with check box, multiple answers.

I have 6 questions. 5 questions are radio button, single answers. Question 6 is checkbox multiple answer. Answers for Q1-Q5 are picked up but Q6 is not. Could someone please tell me what I am doing wrong. I am sure it's a simple thing but I've been staring at it for a while now and am not getting it.

if($HTTP_POST_VARS["q1"] == "c") $correctAnswers++;
if($HTTP_POST_VARS["q2"] == "b") $correctAnswers++;
if($HTTP_POST_VARS["q3"] == "a") $correctAnswers++;
if($HTTP_POST_VARS["q4"] == "d") $correctAnswers++;
if($HTTP_POST_VARS["q5"] == "c") $correctAnswers++;
if($HTTP_POST_VARS["q6"] == "b, c") $correctAnswers++;

switch($correctAnswers)
{
case $correctAnswers < 4:
echo "Keep studying. Total marks: $correctAnswers";
break;

case $correctAnswers >= 5:
echo "Very Good! Total marks: $correctAnswers";
break;

}




Quote Reply
Re: [shaan] $HTTP_POST_VARS - multiple answers In reply to
Wrong place, Internet Technologies is a better place.

Adrian
Quote Reply
Re: [shaan] $HTTP_POST_VARS - multiple answers In reply to
Try this;

Code:
$question6 = $HTTP_POST_VARS["q6"]; // get into an array...

$right1 = 0;
$right2 = 0;

foreach ($question6 as $answer) {

if ($answer eq "b") { $right1 = 1; }
if ($answer eq "c") { $right2 = 1; }

}

if ($right1 && $right2) { $correctAnswers++; }


Its untestested, but the theory should be right Smile

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] $HTTP_POST_VARS - multiple answers In reply to
Thanks Andy! Will try that.