-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeleteBook.php
More file actions
49 lines (40 loc) · 1.3 KB
/
Copy pathDeleteBook.php
File metadata and controls
49 lines (40 loc) · 1.3 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
<?php
$passworddb = "";
// Check if BookID is passed in the URL
if (isset($_GET['BookID'])) {
$BookID = $_GET['BookID'];
// Check if BookID is valid
if (empty($BookID)) {
die("BookID is required.");
}
// Connect to the database
$connection = mysqli_connect("localhost", "root", "", "library");
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}
// Prepare the DELETE query
$query = "DELETE FROM `book` WHERE `BookID` = ?";
$stmt = mysqli_prepare($connection, $query);
if ($stmt) {
// Bind the BookID to the prepared statement
mysqli_stmt_bind_param($stmt, "i", $BookID);
// Execute the statement
if (mysqli_stmt_execute($stmt)) {
echo "Book with ID $BookID has been deleted successfully.";
// Redirect back to the books page after deletion
header("Location: books.php");
exit();
} else {
echo "Error deleting book: " . mysqli_stmt_error($stmt);
}
// Close the prepared statement
mysqli_stmt_close($stmt);
} else {
echo "Error preparing statement: " . mysqli_error($connection);
}
// Close the connection
mysqli_close($connection);
} else {
echo "BookID is missing.";
}
?>