Show sourcecode
The following files exists in this folder. Click to view.
createquiz.php
createtable.php
dbconnection.php
index.php
login.php
myquiz.php
registrera.php
results.php
results2.php
takequiz.php
takequiz.php
58 lines UTF-8 Windows (CRLF)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
<!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
include "dbconnection.php";
$quiz_id = (int)$_GET['id'];
$stmt = $dbconn->prepare("SELECT title FROM quiz WHERE id = :id");
$stmt->execute([':id' => $quiz_id]);
$quiz = $stmt->fetch();
$stmt = $dbconn->prepare("SELECT * FROM questions WHERE quiz_id = :id");
$stmt->execute([':id' => $quiz_id]);
$questions = $stmt->fetchAll();
$formHtml = "";
foreach ($questions as $q) {
$formHtml .= "<p><strong>" . htmlspecialchars($q['question']) . "</strong></p>";
$stmt = $dbconn->prepare(
"SELECT id, answer FROM answers WHERE question_id = :qid"
);
$stmt->execute([':qid' => $q['id']]);
$answers = $stmt->fetchAll();
foreach ($answers as $a) {
$formHtml .= "
<label>
<input type='radio'
name='question_{$q['id']}'
value='{$a['id']}'
required>
" . htmlspecialchars($a['answer']) . "
</label><br>
";
}
}
?>
<h1>Gör quiz</h1>
<form method="post" action="results.php">
<input type="hidden" name="quiz_id" value="<?= $quiz_id ?>">
<?= $formHtml ?>
<br>
<button>Svara</button>
</form>
</body>
</html>