forked from hilderbrandtjohn/shelfindulgence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_book.php
51 lines (43 loc) · 1.36 KB
/
edit_book.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
<?php
// if save change happen
if(!isset($_POST['save_change'])){
echo "Something wrong!";
exit;
}
$isbn = trim($_POST['isbn']);
$title = trim($_POST['title']);
$author = trim($_POST['author']);
$descr = trim($_POST['descr']);
$price = floatval(trim($_POST['price']));
$sname = trim($_POST['sname']);
$scontact = trim($_POST['scontact']);
if(isset($_FILES['image']) && $_FILES['image']['name'] != ""){
$image = $_FILES['image']['name'];
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
$uploadDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . "bootstrap/img/";
$uploadDirectory .= $image;
move_uploaded_file($_FILES['image']['tmp_name'], $uploadDirectory);
}
require_once("./functions/database_functions.php");
$conn = db_connect();
$query = "UPDATE books SET
book_title = '$title',
book_author = '$author',
book_descr = '$descr',
book_price = '$price',
seller_name = '$sname',
seller_contact = '$scontact'";
if(isset($image)){
$query .= ", book_image='$image' WHERE book_isbn = '$isbn'";
} else {
$query .= " WHERE book_isbn = '$isbn'";
}
// two cases for fie , if file submit is on => change a lot
$result = mysqli_query($conn, $query);
if(!$result){
echo "Can't update data " . mysqli_error($conn);
exit;
} else {
header("Location: admin_edit.php?bookisbn=$isbn");
}
?>