Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/anton-quiz/logged-in/
dashboard.php
result.php
test.php
test.php
68 lines UTF-8 Windows (CRLF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
session_start();
if (!$_SESSION["id"]) {
header('Location: ../index.php');
die();
}
require_once __DIR__ . '/../dbconnect.php';
$test_id = $_GET["id"];
$stmt = $conn->prepare("SELECT test_name FROM quizdb_tests WHERE id = ?");
$stmt->bind_param("i", $test_id);
$stmt->execute();
foreach ($stmt->get_result() as $result_name) {
$test_name = $result_name["test_name"];
}
?>
<!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>
<h1><?php echo $test_name; ?></h1>
<form action="../endpoints/check_answers.php" method="post">
<input type="hidden" name="test_id" value="<?php echo $test_id; ?>">
<?php
$one = 1;
$stmt = $conn->prepare("SELECT id, question_text FROM quizdb_questions WHERE is_enabled = ? AND test_id = ?");
$stmt->bind_param("ii", $one, $test_id);
$stmt->execute();
$questionsDbResult = $stmt->get_result();
foreach ($questionsDbResult as $questions) {
?> <h3> <?php echo $questions['question_text']; ?> </h3> <?php
$stmt = $conn->prepare("SELECT id, answer_text FROM quizdb_answers WHERE is_enabled = ? AND question_id = ?");
$stmt->bind_param("ii", $one, $questions["id"]);
$stmt->execute();
$answersDbResult = $stmt->get_result();
foreach ($answersDbResult as $answers) {
?>
<input type="radio" id="answer-<?php echo $answers["id"]; ?>" value="<?php echo $answers["answer_text"]; ?>" name="question-<?php echo $questions["id"]; ?>">
<label for="answer-<?php echo $answers["id"]; ?>"><?php echo $answers["answer_text"]; ?></label>
<br>
<?php
}
}
?>
<button type="submit">Lämna in svar</button>
</form>
</body>
</html>