<?php
// Connect to the database (you should replace these with your own database credentials)
$db = new mysqli('localhost', 'tslibrary_user', 'rb!tsl838', 'tslibrary_data');

// Check for errors in the database connection
if ($db->connect_error) {
    die("Connection failed: " . $db->connect_error);
}

// Retrieve user input from the form
$title = $_POST['title'];
$author = $_POST['author'];
$year = $_POST['year'];
$isbn = $_POST['isbn'];
$rate = $_POST['rate'];
// Insert the book into the database
$sql = "INSERT INTO books (title, author, publication_year, ISBN,rate) VALUES ('$title','$author','$year','$isbn','$rate')";
$stmt = $db->prepare($sql);
$stmt->bind_param("ssis", $title, $author, $year, $isbn);

if ($stmt->execute()) {
    echo "Book added successfully.";
} else {
    echo "Error: " . $stmt->error;
}

$stmt->close();
$db->close();
?>
<?php

header("Location: viewbooks.php");

?>