Solved

Multi choice php problem

Posted on 2006-06-13
4
287 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now