Page 1 of 1

Struggling with a quiz

Posted: Thu Sep 01, 2011 12:03 am
by parkie
Hi everyone, I am struggling to get a multipage quiz working. I am getting this error and don't know what it means and how to fix it
Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\score.php on line 98. I have had a version of this working but not sure what I have done to stuff it up

This is the code I am using. I have all the answers set to 1 at the moment as I'm trying to get it to work. Any help would be greatly appreciated.
Many Thanks
<html>
<body>
<?php

//Checks that all questions have been answered and name entered.

if($_POST['q1']== ''||$_POST['q2']== ''||$_POST['q3']== ''||$_POST['q4']== ''||$_POST['q5']== ''||$_POST['q6']== ''||$_POST['q7']== ''||$_POST['q8']== ''||$_POST['q9']== ''||$_POST['q10'] == ''||$_POST['q11'] == ''||$_POST['q12'] == ''||$_POST['q13'] == ''||$_POST['q14'] == ''||$_POST['q15'] == ''||$_POST['q16'] == ''||$_POST['q17'] == ''||$_POST['q18'] == ''||
$_POST['q19'] == ''||$_POST['q20'] == '')

{
echo '<center><img src = assessment_header.jpg></center><br><br>';
echo "Please go back and enter your name, review and answer all questions.\n";
}
//Checks for correct answers and increases $score if correct.

else
{
$score = 0;
if($_POST['q1'] == 1)
$score++;
if($_POST['q2'] == 1)
$score++;
if($_POST['q3'] == 1)
$score++;
if($_POST['q4'] == 1)
$score++;
if($_POST['q5'] == 1)
$score++;
if($_POST['q6'] == 1)
$score++;
if($_POST['q7'] == 1)
$score++;
if($_POST['q8'] == 1)
$score++;
if($_POST['q9'] == 1)
$score++;
if($_POST['q10'] == 1)
$score++;
if($_POST['q11'] == 1)
$score++;
if($_POST['q12'] == 1)
$score++;
if($_POST['q13'] == 1)
$score++;
if($_POST['q14'] == 1)
$score++;
if($_POST['q15'] == 1)
$score++;
if($_POST['q16'] == 1)
$score++;
if($_POST['q17'] == 1)
$score++;
if($_POST['q18'] == 1)
$score++;
if($_POST['q19'] == 1)
$score++;
if($_POST['q20'] == 1)
$score++;



$score1 = $score /20 * 100; //makes score a precent.
}

if($score1 > 99 )//A score of over 99%

{


$passNumber = file_get_contents("registration");
$passNumber = (int)$passNumber;
$passNumber++;
file_put_contents("registration", $passNumber);



echo '<center><img src = assessment_header.jpg></center><br><br>';
echo "\n";
echo '<center><A HREF = "certsubmit.html"> Congratulations You Have Passed. Click here to complete your certificate </center><br></A>';
echo "\n";
echo "<center>You will be provided with a safety booklet. Please read it, sign and return Declaration page to Head Office or Supervisor before starting work.</center>";

// sends email with name and list of answers.
$to = "info@construction.com";
$subject = " Induction";
$message = "Results for " . $_POST['fname'] . " (#" . $passNumber . "):\n";
$message .= "\n";
$headers = "From: webmaster@bwebsites.com";


for ($i = 1; $i <= 20; $i++)
{
if (isset($_POST['q' . $i]))
$message .= "Answer for question " . $i . ": " . $_POST['q' . $i] . "\n";
}
mail($to, $subject, $message, $headers);

else
{
echo '<center><img src = assessment_header.jpg></center><br><br>';
echo '<center><br><A HREF = "test.html"> Please click here and attempt the Assessment again.</A></center>';
}


?>
</body>
</html>

Re: Struggling with a quiz

Posted: Thu Sep 01, 2011 1:50 am
by Dodon

Code: Select all

for ($i = 1; $i <= 20; $i++)
{
      if (isset($_POST['q' . $i]))
           $message .= "Answer for question " . $i . ": " . $_POST['q' . $i] . "\n";
}
mail($to, $subject, $message, $headers);

else
{
    echo '<center><img src = assessment_header.jpg></center><br><br>';
    echo '<center><br><A HREF = "test.html"> Please click here and attempt the Assessment again.</A></center>';
}

 
you got an else statement without an if statement.

Re: Struggling with a quiz

Posted: Fri Sep 02, 2011 6:14 pm
by parkie
Thank you dodon I had dropped a brace from further up the code.

Re: Struggling with a quiz

Posted: Fri Sep 02, 2011 6:43 pm
by parkie
I thought I had this sorted out but now on my question page I get this error

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\quiz\page1.php:2) in C:\xampp\htdocs\quiz\page1.php on line 3. Any help would be great.
This is the code:

<?php
session_start();

?>
<html>
<body>
<center><img src = assessment_header.jpg></center>
<form action = "page2.php" method = post >
<p> Please Enter Your Name:<input type = "text" name = "fname">