Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/projects/slutprojekt/
class/
create-categories.php
create-recipe.php
css/
db_content.php
forgot_password.php
include/
login.php
logout.php
recipe-search.php
recipe.php
reset_password.php
signin.php
start.php
tabeller/
verify.php
create-categories.php
129 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
123
124
125
126
127
128
129
<?php
session_start();
include('../../dbconnection.php');
ob_clean();
include('include/session-variables.php');
include('class/categoryClass.php');
if($_SESSION['admin'] != true) {
header("Location: login.php");
exit;
}
$category = new Category($dbconn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/styles.css">
<style>
.current2 {
text-decoration:underline !important ;
}
main {
text-align:center;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid black;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.content{
display:grid;
grid-template-columns:1fr 1fr 1fr;
}
.categories-table{
justify-self:left;
}
@media screen and (max-width: 700px){
.content{
grid-template-columns:1fr;
}
.categories-table{
justify-self:center;
}
}
</style>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Skapa kategori</title>
</head>
<body>
<div id="page-container">
<div id="content-wrap">
<?php
include('include/header.php');
?>
<main>
<div class="content">
<div></div>
<div>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['name'])) {
$name = $_POST['name'];
$category->createCategory($name);
echo "<p style='color:green;'>Kategorin '$name' skapades!</p>";
}
?>
<h1>Skapa kategori</h1>
<form action="" method="post">
Skriv in namnet på kategorin: <br>
<input type="text" name="name" required>
<input type="submit" value="Skapa">
</form>
</div>
<div class="categories-table">
<h2>Existerande kategorier:</h2>
<table>
<tr>
<th>Id</th>
<th>Kategorinamn</th>
</tr>
<?php
$sql = "SELECT * FROM categories ORDER BY name ASC";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$categories = $stmt->fetchAll();
if ($categories) {
foreach ($categories as $category) {
echo "<tr>";
echo "<td>" . $category['category_id'] . "</td>";
echo "<td>" . $category['name'] . "</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='2'>Inga kategorier tillgängliga.</td></tr>";
}
?>
</table>
</div>
</div>
</main>
<?php
include('include/footer.php');
?>
</div>
</div>
</body>
</html>