<!DOCTYPE html>
<html>
<head>
    <title>Library - Received Books</title>
</head>
<body>
    <h1>Received Books</h1>
    <ul id="bookList">
        <li data-book-id="1">Book 1 <button class="mark-received">Mark as Received</button></li>
        <li data-book-id="2">Book 2 <button class="mark-received">Mark as Received</button></li>
        <li data-book-id="3">Book 3 <button class="mark-received">Mark as Received</button></li>
    </ul>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const markReceivedButtons = document.querySelectorAll('.mark-received');
            markReceivedButtons.forEach(button => {
                button.addEventListener('click', function() {
                    const bookId = this.parentElement.getAttribute('data-book-id');
                    markBookReceived(bookId);
                });
            });
        });

        function markBookReceived(bookId) {
            const xhr = new XMLHttpRequest();
            xhr.open('POST', 'update.php', true);
            xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
            xhr.onreadystatechange = function() {
                if (xhr.readyState === 4 && xhr.status === 200) {
                    // Handle the response from the server (if needed)
                    // You can update the UI here
                    console.log(xhr.responseText);
                }
            };
            xhr.send('bookId=' + bookId);
        }
    </script>
</body>
</html>
<?php
// Establish a database connection (replace with your database credentials)
$host = "localhost";
$username = "humlogtrust_user";
$password = "Rb!@bh834343";
$database = "humlogtrust_data";

$conn = new mysqli($host, $username, $password, $database);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Handle the AJAX request
if (isset($_POST['bookId'])) {
    $bookId = $_POST['bookId'];

    // You should validate and sanitize input before using it in your SQL query
    // Here, we're using a simple query without input validation for demonstration purposes

    $query = "UPDATE book_allot_receive SET book_receive_date = '123' WHERE ID = '1'";

    if ($conn->query($query) === TRUE) {
        echo "Book received successfully!";
    } else {
        echo "Error updating book: " . $conn->error;
    }
} else {
    echo "Invalid request.";
}

$conn->close();
?>
