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'
$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'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
}
}
?>
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;
}
}
?>
// 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");