forked from vikassinghv34/Book_publish_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminUpdateBook.php
100 lines (77 loc) · 3.73 KB
/
AdminUpdateBook.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
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
<?php include('admin.php');?>
<html>
</head>
<body>
<?php
include "conn.php"; // Using database connection file here
$id = $_GET['id']; // get id through query string
$query = mysqli_query($conn,"select * from books where bookId='$id'"); // select query
$row = mysqli_fetch_array($query); // fetch data
if(isset($_POST['Update'])) // when click on Update button
{
$BookName = $_POST['BookName'];
$BookPrice = $_POST['BookPrice'];
$BookPages = $_POST['BookPages'];
$BookSize = $_POST['BookSize'];
$BookLanguage = $_POST['BookLanguage'];
$BookShortDesc = $_POST['BookShortDesc'];
$BookAuthor = $_POST['BookAuthor'];
$BookPublishyear = $_POST['BookPublishyear'];
$BookCategoryID = $_POST['BookCategoryID'];
$target_dir = "./books/";
$target_file = $target_dir . basename($_FILES["BookImage"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["BookImage"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
$check = getimagesize($_FILES["BookPdf"]["tmp_name"]);
if($check !== false) {
echo "File is an Pdf - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["BookImage"]["tmp_name"], $target_file)) {
$BookImage =$target_dir.$_FILES["BookImage"]["name"];
echo "The file ". htmlspecialchars( basename( $_FILES["BookImage"]["name"])). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$query=mysqli_query($conn," UPDATE `books` SET bookName='$BookName', bookPrice='$BookPrice',bookPages='$BookPages',bookSize='$BookSize',bookLanguage='$BookLanguage',bookShortDesc='$BookShortDesc',bookAuthor='$BookAuthor',bookPublishyear='$BookPublishyear',bookImage='$BookImage', bookPdf='$BookPdf', bookCategoryID='$BookCategoryID' WHERE BookID='$id'");
if($query){
echo '<script>window.location.href = "AdminManageBook.php";</script>';
}else{
echo "Error".$sql."".mysqli_error($conn);
}
// redirects to all records page
}
?>
<h3>Update Data</h3>
<form method="POST" enctype="multipart/form-data">
<input type="text" name="BookName" value="<?php echo $row['bookName'] ?>" placeholder="Enter Name" >
<input type="number" name="BookPrice" value="<?php echo $row['bookPrice'] ?>" placeholder="Enter Price" >
<input type="number" name="BookPages" value="<?php echo $row['bookPages'] ?>" placeholder="Enter Pages" >
<input type="numer" step="any" name="BookSize" value="<?php echo $row['bookSize'] ?>" placeholder="Enter size" >
<input type="text" name="BookLanguage" value="<?php echo $row['bookLanguage'] ?>" placeholder="Enter Price" >
<input type="text" name="BookShortDesc" value="<?php echo $row['bookShortDesc'] ?>" placeholder="Enter Short Description" >
<input type="text" name="BookAuthor" value="<?php echo $row['bookAuthor'] ?>" placeholder="Enter Author" >
<input type="number" name="BookPublishyear" value="<?php echo $row['bookPublishyear'] ?>" placeholder="Enter Publish Year" >
<input type="file" name="BookImage" value="<?php echo $row['bookImage'] ?>" required>
<input type="file" name="BookPdf" value="<?php echo $row['bookPdf'] ?>" required>
<input type="number" name="BookCategoryID" value="<?php echo $row['bookCategoryId'] ?>" placeholder="Enter Ctegory ID" >
<input type="submit" name="Update" value="Update">
</form>