I want it so if not all the questions were answered, you'll get a message asking you to go back and answer all the questions. I tried a few different ways to achieve this, but everything I tried caused the message to always come up, even if all the questions were answered it would still say "please answer all".
Here's the code for the quiz, can you fix it up so it requires every question to be answered.
quiz.php
Is this correct?<br />
<input name="q[1]" type="radio" value="yes" />Yes<br />
<input name="q[1]" type="radio" value="no" />No<br />
<br />
Is this correct?<br />
<input name="q[2]" type="radio" value="yes" />Yes<br />
<input name="q[2]" type="radio" value="no" />No<br />
<br />
Is this correct?<br />
<input name="q[3]" type="radio" value="yes" />Yes<br />
<input name="q[3]" type="radio" value="no" />No<br />
<br />
THERE ARE 10 OF THESE
quizresults.php
//------- Variables ------------------------------------
// Name
$name = htmlspecialchars($_POST['name']);
// Mailing
$sendto = "REMOVE@REMOVE";
$subject = "the quiz";
$content = "Name: {$name}\n\n";
$content .= print_r($_POST['q'], true);
$headers = "From: Quiz Answers\n";
//------------------------------------------------------
$count = 0;
$total = 10;
if (is_array($_POST['q'])) {
foreach ($_POST['q'] as $value) {
if ($value == 'yes') {
++$count;
}
}
}
echo "<h1>Hello <span style='color:red'>" . $_POST['name'] . "</span></h1>";
printf("<h1>You are %d%% correct.</h1>", round($count / $total * 100));
mail($sendto, $subject, $content, $headers);