Solved

Multi choice php problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

914 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

19 Experts available now in Live!

Get 1:1 Help Now