-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue_book.php
More file actions
46 lines (39 loc) · 1.47 KB
/
Copy pathissue_book.php
File metadata and controls
46 lines (39 loc) · 1.47 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
<?php
session_start();
if (!isset($_SESSION['username'])) {
header("Location: login1.php"); // ✅ Redirect to index.html instead of login.php
exit();
}
?>
<?php
include 'db_connection.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$student_id = $_POST['student_id'];
$book_id = $_POST['book_id'];
$issue_date = date('Y-m-d');
// Check if the student exists in the Students table
$student_check_query = "SELECT * FROM Students WHERE student_id='$student_id'";
$student_result = mysqli_query($conn, $student_check_query);
if (mysqli_num_rows($student_result) == 0) {
echo "Error: Student ID not found. Please add the student first.";
exit;
}
// Check if the book is available
$check_query = "SELECT status FROM Books WHERE book_id='$book_id'";
$result = mysqli_query($conn, $check_query);
$book = mysqli_fetch_assoc($result);
if ($book['status'] == 'Available') {
$query = "INSERT INTO Transactions (student_id, book_id, issue_date, status)
VALUES ('$student_id', '$book_id', '$issue_date', 'Issued')";
$update_book_status = "UPDATE Books SET status='Issued' WHERE book_id='$book_id'";
if (mysqli_query($conn, $query) && mysqli_query($conn, $update_book_status)) {
echo "✅ Book issued successfully!";
} else {
echo "❌ Error: " . mysqli_error($conn);
}
} else {
echo "⚠ Book is already issued.";
}
exit;
}
?>