-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_book.php
More file actions
38 lines (32 loc) · 1.19 KB
/
Copy pathdelete_book.php
File metadata and controls
38 lines (32 loc) · 1.19 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
<?php
include 'db_connection.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$book_id = $_POST['book_id'];
// Pehle transactions delete karo
$delete_transactions = "DELETE FROM transactions WHERE book_id = '$book_id'";
mysqli_query($conn, $delete_transactions);
// Ab book delete karo
$delete_book = "DELETE FROM books WHERE book_id = '$book_id'";
mysqli_query($conn, $delete_book);
// Check karo ki books table empty ho gaya ya nahi
$check_books = mysqli_query($conn, "SELECT COUNT(*) as total FROM books");
$row = mysqli_fetch_assoc($check_books);
if ($row['total'] == 0) {
// Agar koi book nahi bacha to auto-increment reset karo
mysqli_query($conn, "ALTER TABLE books AUTO_INCREMENT = 1");
}
echo "<script>
window.onload = function() {
Swal.fire({
icon: 'success',
title: 'Deleted!',
text: 'Book deleted successfully.',
confirmButtonColor: '#3085d6'
}).then(() => {
window.location.href='view_books.php';
});
};
</script>";
}
?>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>