Solved

Multi choice php problem

Posted on 2006-06-13
4
317 Views
Last Modified: 2010-04-17
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'
0
Comment
Question by:roscoeh23
  • 3
4 Comments
 
LVL 8

Expert Comment

by:Autogard
ID: 16894836
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");
0
 
LVL 8

Accepted Solution

by:
Autogard earned 500 total points
ID: 16894957
Then you will need to read that variable in php as follows:

<?php

// Store the variable we just passed (will be empty if there was no "?page=<value>" passed.
$page = $_REQUEST["page"];

// This is what they get when they are directed to the 2nd page from the first, etc...
if($page != "")
{
    print "Congratulations!  You got it right!<br>";
    print "Here is question #$pageNumber:<br>";
}
// This is what they get the first time they access the page
else
{
    print "Here is the first question:<br>";
    $page = 1;
}

// Now print out the question and check the answers

?>
0
 

Author Comment

by:roscoeh23
ID: 16909715
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;
}
}


?>
0
 
LVL 8

Expert Comment

by:Autogard
ID: 16912321
This might help with that...

http://www.alt-php-faq.org/local/15/

and

www.php.net/header
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question