I am doing a baseball quiz and one of the questions requires the use of checkboxes since it has multiple answers. The question is irrelevant but here is what I have for the code:
<input type="checkbox" name="Player 1" value="Player 1" />Player 1
<input type="checkbox" name="Player 2" value="Player 2" />Player 2
<input type="checkbox" name="Player 3" value="Player 3" />Player 3
<input type="checkbox" name="Player 4" value="Player 4" />Player 4
<input type="checkbox" name="Player 5" value="Player 5" />Player 5
<input type="checkbox" name="Player 6" value="Player 6" />Player 6
Let's say the correct answer is Players 2, 3, and 6. Here is what I am doing:
if(isset($_POST['Player 2']) && isset($_POST['Player 3']) && isset($_POST['Player 6'])) { // Check if 2, 3, and 6 are checked
print "<p>Your answer is correct!</p>";
$correct++;
} else {
print "<p>Your answer is incorrect.</p>";
}
I tried testing this by selected Players 2, 3, and 6 which are the right answers, but my program still said my answer was incorrect. I tried putting in debugging statements to see if the values are being stored correctly and they are not. For instance when I tried to say:
if(isset($_POST['Player 2'])) {
$p2 = $_POST['Player 2'];
}
.....
print "<p>The answer is " . $p2 . ".</p>";
It would print the string "The answer is ." which means its not getting the value at all. How can I fix this?
Aucun commentaire:
Enregistrer un commentaire