Untitled
unknown
plain_text
16 days ago
1.9 kB
2
Indexable
Never
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Quiz</title> </head> <body> <h1> Quiz </h1> <br> <p><b>Instructions: <b> Answer the following mathematical questions. Use numbers only </p> <br> <form method="POST" action="result.php"> <label>Quiz</label> <br> <label>1. 1+1 = </label> <input type="text" name="ans-1" required> <br> <label>2. 2+2 = </label> <input type="text" name="ans-2" required> <br> <label>3. 3+3 = </label> <input type="text" name="ans-3" required> <br> <label>4. 4+4 = </label> <input type="text" name="ans-4" required> <br> <label>5. 5+5 = </label> <input type="text" name="ans-5" required> <br> <input type="submit"> </form> </body> </html> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <?php $user_answer = array ($_POST['ans-1'],$_POST['ans-2'],$_POST['ans-3'],$_POST['ans-4'],$_POST['ans-5']); $correct_answer = array (2,4,6,8,10); $score = 0; for ($i = 0; $i < count($user_answer); $i++) { if($user_answer[$i] == $correct_answer[$i]){ $score += 1; } } echo "<h1> Quiz Results </h1>"; echo "<br>"; echo "<h2> Total Score: $score / 5 </h2>"; echo "<h3>Correct Answers: </h3>"; for ($i = 0; $i < count($user_answer); $i++) { echo "<ul>"; if($user_answer[$i] == $correct_answer[$i]){ echo "<li>Question " . ($i + 1) . " : " .$correct_answer[$i] . "</li>"; } echo "</ul>"; } ?> </body> </html>
Leave a Comment