-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_book.php
More file actions
executable file
·73 lines (56 loc) · 1.59 KB
/
delete_book.php
File metadata and controls
executable file
·73 lines (56 loc) · 1.59 KB
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
<?php
session_start();
if (isset($_COOKIE['admin'])) {
$_SESSION['admin'] = $_COOKIE['admin'];
}
if (!isset($_SESSION['admin'])) {
header("Location: login.php");
exit();
}
?>
<?php
/*
// Include database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "shehda_library_db";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
*/
// include "db_connect.php";
require_once "db_connect.php"; // require once is better than include, because the database connection is important.
// Check if book ID is provided
if (!isset($_GET['id']) || empty($_GET['id'])) {
die("Invalid book ID.");
}
$book_id = $_GET['id'];
// Delete book from the database
$sql = "DELETE FROM books WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $book_id);
if ($stmt->execute()) {
echo "<script>alert('Book deleted successfully!'); window.location='index.php';</script>";
} else {
echo "Error deleting book: " . $conn->error;
}
/*
if ($_GET['available']){
// Delete book from the database
$sql = "DELETE FROM books WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $book_id);
if ($stmt->execute()) {
echo "<script>alert('Book deleted successfully!'); window.location='index.php';</script>";
} else {
echo "Error deleting book: " . $conn->error;
}
}
else{
echo "You can't delete a borrowed book";
}
*/
$conn->close();
?>