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
create_quiz.php
61 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
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
include('../../incl/dbconnect.php');
$user_id = $_SESSION['user_id'];
// Kontrollera att användaren är administratör
$stmt = $dbconn->prepare("SELECT is_admin FROM users_quiz WHERE id = ?");
$stmt->execute([$user_id]);
$is_admin = $stmt->fetchColumn();
if (!$is_admin) {
echo "Åtkomst nekad. Du är inte administratör.";
exit;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<title>Skapa Quiz</title>
<link rel="stylesheet" href="nav.css">
</head>
<body>
<?php include 'nav.php'; ?>
<h1>Skapa nytt quiz</h1>
<form action="submit_create_quiz.php" method="post">
<h2>Testinformation</h2>
<label for="titel">Titel:</label>
<input type="text" name="titel" id="titel" required><br>
<label for="beskrivning">Beskrivning:</label>
<textarea name="beskrivning" id="beskrivning" rows="4" cols="50"></textarea><br>
<h2>Frågor och svar</h2>
<?php for ($i = 1; $i <= 5; $i++): ?>
<fieldset>
<legend>Fråga <?php echo $i; ?></legend>
<label for="fraga_<?php echo $i; ?>">Fråga:</label>
<input type="text" name="fraga_text[<?php echo $i; ?>]" id="fraga_<?php echo $i; ?>" required><br>
<p>Svarsalternativ:</p>
<?php for ($j = 1; $j <= 3; $j++): ?>
<label for="svar_<?php echo $i.'_'.$j; ?>">
<input type="radio" name="korrekt[<?php echo $i; ?>]" value="<?php echo $j; ?>" required>
Rätt svar?
</label>
<input type="text" name="svar_text[<?php echo $i; ?>][<?php echo $j; ?>]" id="svar_<?php echo $i.'_'.$j; ?>" required><br>
<?php endfor; ?>
</fieldset>
<br>
<?php endfor; ?>
<input type="submit" value="Skapa Quiz">
</form>
</body>
</html>