-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn_book.php
59 lines (49 loc) · 1.67 KB
/
return_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
52
53
54
55
56
57
58
59
<?php
session_start();
// Check if the user is logged in as staff
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'staff') {
header('Location: login.html');
exit();
}
// Database connection
$host = 'localhost';
$db = 'dbms';
$user = 'root';
$pass = '';
$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
die('Connection failed: ' . $conn->connect_error);
}
// Return book
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['return_book'])) {
$transaction_id = $_POST['transaction_id'];
$return_date = date('Y-m-d');
// Update transaction with return date
$stmt = $conn->prepare("UPDATE transactions SET return_date = ? WHERE transaction_id = ?");
$stmt->bind_param('si', $return_date, $transaction_id);
$stmt->execute();
$stmt->close();
// Update available copies of the book
$stmt = $conn->prepare("UPDATE books SET available_copies = available_copies + 1 WHERE book_id = (SELECT book_id FROM transactions WHERE transaction_id = ?)");
$stmt->bind_param('i', $transaction_id);
$stmt->execute();
$stmt->close();
echo "Book returned successfully!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Return Book</title>
</head>
<body>
<h2>Return Book</h2>
<form action="return_book.php" method="POST">
<label for="transaction_id">Transaction ID</label>
<input type="text" name="transaction_id" required><br>
<button type="submit" name="return_book">Return Book</button>
</form>
</body>
</html>