Solved

Multi choice php problem

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Plain Text Editor for iPad 6 105
ejb stateless example 2 40
SQL Insert parts by customer 12 53
WordPress: Debugging from my Windows 10 Desktop 6 61
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.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

762 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