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-recipe.php
106 lines ASCII 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
<?php
session_start();
if($_SESSION['admin'] != true) {
header("Location: login.php");
exit;
}
include('../../dbconnection.php');
ob_clean();
include('include/header.php');
include('include/session-variables.php');
include('class/recipeClass.php');
$recipe = new Recipe($dbconn);
$user_id = $_SESSION['userId'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.current1 {
text-decoration:underline !important ;
}
#content-wrap {
text-align:center;
}
.select{
width: 150px;
height: 260px;
font-size: 14px;
padding: 2px;
border-radius: 5px;
}
</style>
<link rel="stylesheet" href="css/styles.css">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Skapa Recept</title>
</head>
<body>
<div id="page-container">
<div id="content-wrap">
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['title'])
&& isset($_POST['ingredients']) && isset($_POST['instructions']) && isset($_FILES['image'])) {
$title = trim(htmlspecialchars($_POST['title']));
$ingredients = trim(htmlspecialchars($_POST['ingredients']));
$instructions = trim(htmlspecialchars($_POST['instructions']));
$image = null;
if ($_FILES['image']['error'] == 0) {
$image = '../../../filhantering/' . basename($_FILES['image']['name']);
move_uploaded_file($_FILES['image']['tmp_name'], $image);
}
$categories = isset($_POST['categories']) ? $_POST['categories'] : [];
$recipe->createRecipe($title, $ingredients, $instructions, $image, $user_id, $categories);
echo "<p style='color:green;'>Receptet '$title' skapades!</p>";
}
?>
<h1>Skapa Recept</h1>
<form action="" method="post" enctype="multipart/form-data">
Titel:<br>
<input type="text" name="title" size="35" required> <br> <br>
Ingredienser: <br>
<textarea name="ingredients" cols="35" rows="15" required></textarea> <br> <br>
Instruktioner: <br>
<textarea name="instructions" cols="35" rows="15" required></textarea> <br> <br>
Bild <br>
<input type="file" name="image"> <br> <br>
Kategorier <br>
<select name="categories[]" multiple required class="select">
<?php
$sql = "SELECT * FROM categories ORDER BY name ASC";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$categories = $stmt->fetchAll();
foreach ($categories as $category) {
echo "<option value='" . $category['category_id'] . "'>" . $category['name'] . "</option>";
}
?>
</select><br><br>
<input type="submit" value="Skapa Recept">
</form>
<?php
include('include/footer.php');
?>
</div>
</div>
</body>
</html>