-
Notifications
You must be signed in to change notification settings - Fork 34
/
new.php
62 lines (49 loc) · 1.7 KB
/
new.php
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
<?php
//připojení k databázi
require 'db.php';
//přístup jen pro admina
require 'admin_required.php';
if (!empty($_POST)){
$formErrors='';
//TODO tady by měly být nějaké kontroly odeslaných dat, že :)
if (empty($formErrors)){
#region uložení zboží do DB
$stmt = $db->prepare("INSERT INTO goods(name, description, price) VALUES (:name, :description, :price)");
$stmt->execute([
':name'=>$_POST['name'],
':description'=>$_POST['description'],
':price'=>floatval($_POST['price'])
]);
#endregion uložení zboží do DB
}
//přesměrování na homepage
header('Location: index.php');
exit();
}
?><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>PHP Shopping App</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<?php include 'navbar.php' ?>
<h1>New goods</h1>
<?php
if (!empty($formErrors)){
echo '<p style="color:red;">'.$formErrors.'</p>';
}
?>
<form method="post">
<label for="name">Name</label><br/>
<input type="text" name="name" id="name" value="<?php echo htmlspecialchars(@$_POST['name']);?>" required><br/><br/>
<label for="price">Price<br/>
<input type="number" min="0" name="price" id="price" required value="<?php echo htmlspecialchars(@$_POST['price'])?>"><br/><br/>
<label for="description">Description</label><br/>
<textarea name="description" id="description"><?php echo htmlspecialchars(@$_POST['description'])?></textarea><br/><br/>
<br/>
<input type="submit" value="Save"> or <a href="index.php">Cancel</a>
</form>
</body>
</html>