Show sourcecode
The following files exists in this folder. Click to view.
adminlogin.php
createtables.php
createtest.php
dbconnection.php
index.php
kundsida.php
result.php
test.php
kundsida.php
122 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
include('dbconnection.php');
session_start();
$warningMsg = "";
if (isset($_POST["submit"])) {
$_SESSION['testnumber'] = $_POST["test"];
unset($_POST['submit']);
header("Location: test.php");
}
if ($_SESSION["logIn"] == false) {
header("Location: index.php");
}
if (isset($_POST["logout"])) {
$_SESSION["userid"] = 0;
$_SESSION["logIn"] = false;
header("Location: index.php");
}
try {
$sql = "SELECT COUNT(*) FROM testinfo";
$res = $dbconn->query($sql);
$count = $res->fetchColumn();
} catch (PDOException $e) {
echo $sql . "<br />" . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table {
border: 1px black solid;
}
td {
width: 150px;
}
tr {
width: 100px;
}
th {
width: 100px;
text-align: center;
background-color: grey;
}
</style>
</head>
<body>
<nav>
<a href="index.php">Login</a> <br>
<a href="result.php">Resultat</a> <br>
<a href="kundsida.php">Kundsida</a> <br>
<a href="adminlogin.php">Admin</a>
</nav>
<header>
<h1>Välkommen, välj ett test nedan:</h1>
<form action="" method="post">
<input type="submit" name="logout" value="Logga ut">
</form>
</header>
<main>
<form action="" method="post">
<div>
<?php
for ($i = 1; $i <= $count; $i++) {
// echo "<input type= \"radio \" name = \"test\" value= \"test.$i.\" id= \"test.$i.\"> <label for= \"test.$i.\">HTML</label><br> <br>";
echo "<input type='radio' id='$i' name='test' value='$i'>
<label for='$i'>Test $i</label><br><br>";
}
?>
</div>
<input type="submit" name="submit">
</form>
</main>
<footer>
<h2>Eller visa resultat:</h2>
<h2>Gjorda tester:</h2>
<div>
<?php
$userid = $_SESSION['userid'];
try {
$sql = "SELECT testid, amountcorrect, test_date FROM testresults WHERE userid = $userid";
$stmt = $dbconn->prepare($sql);
$data = array();
$stmt->execute($data);
$output = "<h1>Tester!</h1><table>
<tr>
<th> Test </th>
<th> Antal Rätt </th>
<th> Datum </th>
</tr>
";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>" .
"<td>" . htmlentities($res['testid']) . "</td>" .
"<td>" . htmlentities($res['amountcorrect']) . "</td>" .
"<td>" . htmlentities($res['test_date']) . "</td>" .
"</tr>";
}
$output .= "</table>";
echo "$output";
} catch (PDOException $e) {
echo $sql . "<br />" . $e->getMessage();
}
$dbconn = null;
?>
</div>
</footer>
</body>
</html>