Show sourcecode
The following files exists in this folder. Click to view.
account.php
admin_register.php
create_quiz.php
create_tables.php
index.php
login.php
nav.css
nav.php
quiz.php
quiz_select.php
register.php
result_details.php
result_simple.php
submit_create_quiz.php
submit_quiz.php
result_details.php
88 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
session_start();
include ('../../incl/dbconnect.php');
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
if (!isset($_GET['test_id']) || empty($_GET['test_id'])) {
echo "Test-ID saknas.";
exit;
}
// Kontrollera om test_id skickats me GET
if (isset($_GET['test_id']) && !empty($_GET['test_id'])) {
$test_id = $_GET['test_id'];
} else {
die("Fel: test_id saknas!");
}
// Debugging
// echo "Test-ID: " . htmlspecialchars($test_id);
$user_id = $_SESSION['user_id'];
$test_id = $_GET['test_id'];
// Hämta testets titel
$stmt = $dbconn->prepare("SELECT titel FROM testinfo_quiz WHERE id = ?");
$stmt->execute([$test_id]);
$test = $stmt->fetch(PDO::FETCH_ASSOC);
// Hämta användarens resultat
$stmt = $dbconn->prepare("
SELECT ua.fråga_id, ua.valt_svar_id, ua.korrekt, q.fråga_text, a.svar_text AS user_answer, ca.svar_text AS correct_answer
FROM user_answers_quiz ua
JOIN questions_quiz q ON ua.fråga_id = q.id
JOIN answers_quiz a ON ua.valt_svar_id = a.id
JOIN answers_quiz ca ON ca.fråga_id = q.id AND ca.korrekt = 1
WHERE ua.resultat_id IN (SELECT id FROM results_quiz WHERE kund_id = ? AND test_id = ?)
");
$stmt->execute([$user_id, $test_id]);
$answers = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>Dina resultat - <?php echo htmlspecialchars($test['titel']); ?></title>
<link rel="stylesheet" href="nav.css">
<style>
.correct { color: green; font-weight: bold; }
.incorrect { color: red; font-weight: bold; }
</style>
</head>
<body>
<?php include ('nav.php'); ?>
<h2>Dina resultat för "<?php echo htmlspecialchars($test['titel']); ?>"</h2>
<?php if (!empty($answers)): ?>
<ul>
<?php foreach ($answers as $row): ?>
<li>
<strong><?php echo htmlspecialchars($row['fråga_text']); ?></strong><br>
Ditt svar:
<span class="<?php echo $row['korrekt'] ? 'correct' : 'incorrect'; ?>">
<?php echo htmlspecialchars($row['user_answer']); ?>
</span>
<br>
<?php if (!$row['korrekt']): ?>
Rätt svar: <span class="correct"><?php echo htmlspecialchars($row['correct_answer']); ?></span>
<?php endif; ?>
</li>
<hr>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p>Du har inte gjort detta test än</p>
<?php endif; ?>
<a href="index.php">Tillbaka till startsidan</a>
</body>
</html>