I am putting together a pretty simple quiz. It starts with a form where you enter your name and email, and then moves into questions which span 5 screens, 5 questions per screen. All we want this app to do is show people their name and score at the end of the quiz, and send their email to us for our e-mail list stored in-house.
I have a file, start.php. This is a simple html form that collects the name (name=testtaker) and email (name=testemail) data. This data is submitted to a file labelled questions.php.
questions.php is where i start up sessions:
session_start();
header("Cache-control: private");
if (!$_SESSION['testtaker']) {
$_SESSION['testtaker'] = $testtaker;
}
if (!$_SESSION['testemail']) {
$_SESSION['testemail'] = $testemail;
}
So far, so good. I echo the session variables to the screen to make sure they are there, and they are.
Next questions.php calls up (include_once) the first form with 5 questions. The form action is questions.php and when I submit, the idea is to just process their answers -- yes/no questions where each yes is worth one point. This is where things go south and I lose my previously created session data.
questions.php basically just goes like this:
(1) start up the session and register the user info if not already there.
(2) display quiz screen one, and process score data upon submit -- score data is stored in a hidden field which i simply add up after each screen.
(3) call up quiz screen two and process score data upon submit.
(4) and on through screen five which is then processed on a "final.php" screen where the score is captured and registered as a session variable -- $_SESSION['score'].
That's where my other problem happens. The score variable just simply doesn't register.
Lastly, I want to echo $SESSION['score'], $SESSION['testtaker'], and $_SESSION['testemail'] to the screen and/or use in a mail message generated in the results.php page. But since these are lost, or never registered, I end up with nothing.
All of my php pages start with session_start(). I didn't use variable names that can be confused with global variables - I don't think. I don't get why I'm losing my session info, esp since I'm doing hardly anything with it. Is there something I'm missing? Appreciate your help!