Link to home
Start Free TrialLog in
Avatar of roscoeh23
roscoeh23

asked on

Multi choice php problem

I have a multi choice quiz and the questions and answers are stored in a external file...


$q1 = "what is the capital of Sotland ";

$a1 = "Edinburgh";

$b1 ="Glasgow";

$c1 ="dundee";

$d1 ="Stirling";


$q1_answer = $a1;

?>

The answer is compared..



if  ($_POST['x']== $q1_answer) {

// i need to know what to do here

}
else {
$chances++;
echo "you have had".$chances;
}
}


what I need to do is if they get the question right self submit a $page variable and increment it by 1. I do not know how to self submit in this way. Maybe some javascript? Something like this?

http://mypage.com?page='$page+1'
Avatar of Autogard
Autogard

You can do that right in PHP.

// i need to know what to do here
//assuming you have the $page variable established already
$incrementedPage = $page + 1;
header("Location: http://mypage.com?page=$incrementedPage");
ASKER CERTIFIED SOLUTION
Avatar of Autogard
Autogard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of roscoeh23

ASKER

using the location header gives the headers alredy sent error....

session_start();

if (!isset($_SESSION['chances'])) {
$chances = $_SESSION['chances'] = '0';
}
else {
$chances = $_SESSION['chances'];
}


include "../multi.php";

if (isset($_POST['Submit'])) {

if  ($_POST['x']== $q1_answer) {

$incrementedPage = $page + 1;
header("Location: http://mypage.com?page=$incrementedPage");
}
else {

$chances++;
echo "you have had".$chances;
}
}


?>