Solved

Multi choice php problem

Posted on 2006-06-13
4
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Six Sigma Control Plans

634 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