I want to make a quiz test in PHP so that it will instantly show in every page if the answer chosen by the user is correct or not. So my quiz test will be shown as a question per page, please explain and show me how to modify the following code so that I will know what to do in the other pages:
<main>
<div class="big-div">
<p>1. Which is the biggest planet in our Solar System?</p>
<form method="POST">
<label class="container"> A) Uranus
<input type="radio" name="biggestplanet" value="uranus">
<span class="checkmark"></span>
</label>
<label class="container"> B) Saturn
<input type="radio" name="biggestplanet" value="saturn">
<span class="checkmark"></span>
</label>
<label class="container"> C) Jupiter
<input type="radio" name="biggestplanet" value="jupiter">
<span class="checkmark"></span>
</label>
<label class="container"> D) Neptune
<input type="radio" name="biggestplanet" value="neptune">
<span class="checkmark"></span>
</label>
<input type="submit" value="Send" class="submit">
</form>
<?php
$answer1 = $_POST["getAttribute('biggestplanet')"];
if ($answer1 == "C) Jupiter") {
echo "<p style='color:red;font-size:20px;'>Correct answer!</p>";
} else {
echo "<p style='color:red;font-size:20px;'>Wrong answer! The biggest planet in out Solar System is Jupiter!</p>";
}
?>
So, briefly, this is my PHP code that I can't figure out how to write it correctly:
<?php
$answer1 = $_POST["getAttribute('biggestplanet')"];
if ($answer1 == "C) Jupiter") {
echo "<p style='color:red;font-size:20px;'>Correct answer!</p>";
} else {
echo "<p style='color:red;font-size:20px;'>Wrong answer! The biggest planet in out Solar System is Jupiter!</p>";
}
?>
I'm not for the moment interested in how to send the answers to a database, I just want to know how to show to the user if his answers are correct or not.