Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/projects/anton-quiz/logged-in/
dashboard.php
result.php
test.php
dashboard.php
65 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
<?php
session_start();
if (!$_SESSION["id"]) {
header('Location: ../index.php');
die();
}
require_once __DIR__ . '/../dbconnect.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard</title>
</head>
<body>
<h1>Startsida</h1>
<div>
<h2>Tester du kan göra:</h2>
<?php
$one = 1;
$stmt = $conn->prepare('SELECT * FROM quizdb_tests WHERE is_enabled = ?');
$stmt->bind_param("i", $one);
$stmt->execute();
$testsDbResult = $stmt->get_result();
foreach ($testsDbResult as $tests) {
?>
<a href="test.php?id=<?php echo $tests['id']; ?>"><?php echo $tests["test_name"] ?></a>
<?php
// Kontrollera om användaren gjort ett test tidigare
$stmt = $conn -> prepare('SELECT id FROM quizdb_results WHERE user_id = ? AND test_id = ?');
$stmt -> bind_param('ii', $_SESSION["id"], $tests["id"]);
$stmt -> execute();
$resultsDbResult =$stmt -> get_result();
if (mysqli_num_rows($resultsDbResult) > 0) {
?>
<!-- Kolla user med session i result.php -->
<a href="result.php?test_id=<?php echo $tests['id']?>">Resultat: <?php echo $tests["test_name"] ?></a><br>
<?php
}
?>
<?php
}
?>
</div>
<a href="../endpoints/log-out.php">Logga ut</a>
</body>
</html>