I'm working on a quiz page using PHP with which I'm not very familiar. The current page features with question 6. I cannot get that question's correct answer to be declared as correct.
Here's the PHP form action markup:
. . .
// Question 6
$questionnumber = "6"; // What question number is this?
$nextquestion = $questionnumber + 1;
if ( $_GET[ 'question' ] == $questionnumber ) {
$answer = $_POST[ 'answer' ]; // Gets the submitted answer
$correctanswer = "a false god of the Philistines"; // The correct answer for the previous question
// Here you can edit the form, question and answers
$question = 'Samuel was displeased when the people of Israel demanded of him, “Give us a king to lead us.” So Samuel prayed to the Lord who told him (8:7):';
$form = '
<form action="?question=' . $nextquestion . '" method="post">
' . $question . '<br><br>
<input type="radio" name="answer" id="“Repent: for the kingdom of heaven is at hand.”" value="“Repent: for the kingdom of heaven is at hand.”" /><label for="“Repent: for the kingdom of heaven is at hand.”">“Repent: for the kingdom of heaven is at hand.”</label><br>
<input type="radio" name="answer" id="“It is not you they have rejected; they have rejected me as their king.”" value="“It is not you they have rejected; they have rejected me as their king.”" /><label for="“It is not you they have rejected; they have rejected me as their king.”">“It is not you they have rejected; they have rejected me as their king.”</label><br>
<input type="radio" name="answer" id="“Love your enemies, bless them who curse you.”" value="“Love your enemies, bless them who curse you.”" /><label for="“Love your enemies, bless them who curse you.”">“Love your enemies, bless them who curse you.”</label><br>
<input type="radio" name="answer" id="“Get thee hence, Satan!”" value="“Get thee hence, Satan!”" /><label for="“Get thee hence, Satan!”">“Get thee hence, Satan!”</label><br>
<br>
<input type="submit" value="Answer this question" />'; // Do not include </form> here or it won't calculate as-you-go scores . . .
. . .
And here's the markup for the correct answer that fits atop the question 7 container:
. . .
// Question 7
$questionnumber = "7"; // What question number is this?
$nextquestion = $questionnumber + 1;
if ( $_GET[ 'question' ] == $questionnumber ) {
$answer = $_POST[ 'answer' ]; // Gets the submitted answer
$correctanswer = "“It is not you they have rejected; they have rejected me as their king.”"; // The correct answer for the previous question
. . .
I've copy/pasted the correct answer from the form — it's the second of four multiple-choice options beginning with "It is not you." — into the "?correctanswer =" field. Alas, I continually clear the cache files yet keep getting an incorrect answer while that answer is correct! I suspect I've entered an PHP syntax error without realizing it. Would you please advise me how to correct my "answer" entry so it'll be declared as correct?
Here's the PHP page that you'l want to test for yourself:
https://www.warrencampdesign.com/heartyBoys/quizzes/quiz1Samuel.php?question=6
Many thanks in advance,
Warren