-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathedit.php
More file actions
44 lines (30 loc) · 869 Bytes
/
edit.php
File metadata and controls
44 lines (30 loc) · 869 Bytes
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
<?php
require_once 'include/common.php';
require_once 'include/protect.php';
$errors = [
isMissingOrEmpty ('title', $_POST['title']),
isMissingOrEmpty ('isbn13', $_POST['isbn13']),
isMissingOrEmpty ('price', $_POST['price']),
];
// remove all the empty elements
$errors = array_filter($errors);
if (!isEmpty($errors)) {
$_SESSION['errors'] = $errors;
include "edit-view.php";
exit();
}
$dao = new BookDAO();
$book = new Book();
$book->title = $_POST['title'];
$book->isbn13 = $_POST['isbn13'];
$book->price = $_POST['price'];
$errors = array_merge($errors,checkError($book,["title","isbn13","price"]));
if (!isEmpty($errors)) {
$_SESSION['errors'] = $errors;
include "edit-view.php";
exit();
}
$dao->modify($book);
// send back to listing page
header("Location: list-view.php");
?>