From b8e3ea42360642d4ccfe8f084d2bf0d9d138dfe5 Mon Sep 17 00:00:00 2001 From: Lokesh Patra Date: Sun, 17 Nov 2024 12:22:40 +0530 Subject: [PATCH] LM '24 [ v4 Featured /Fashioned /Finished ] --- add_book.css | 95 +++++++++++++++++++++++++++++++++ add_book.html | 44 ++++++++++++++++ add_book.php | 101 +++++++++++++++++++++++++++++++++++ books.json | 30 +++++++++++ books.xml | 2 + common.css | 48 +++++++++++++++++ dashboard.css | 62 ++++++++++++++++++++++ dashboard.html | 23 ++++++++ dashboard.php | 23 ++++++++ db_config.php | 16 ++++++ export_books.php | 15 ++++++ export_books.py | 40 ++++++++++++++ index.css | 132 ++++++++++++++++++++++++++++++++++++++++++++++ index.html | 48 +++++++++++++++++ index.php | 44 ++++++++++++++++ login.css | 92 ++++++++++++++++++++++++++++++++ login.html | 27 ++++++++++ login.php | 25 +++++++++ logout.php | 15 ++++++ navbar.php | 115 ++++++++++++++++++++++++++++++++++++++++ register.css | 99 ++++++++++++++++++++++++++++++++++ register.html | 28 ++++++++++ register.php | 30 +++++++++++ search.js | 34 ++++++++++++ search_books.css | 131 +++++++++++++++++++++++++++++++++++++++++++++ search_books.html | 103 ++++++++++++++++++++++++++++++++++++ search_books.php | 41 ++++++++++++++ validation.js | 13 +++++ 28 files changed, 1476 insertions(+) create mode 100644 add_book.css create mode 100644 add_book.html create mode 100644 add_book.php create mode 100644 books.json create mode 100644 books.xml create mode 100644 common.css create mode 100644 dashboard.css create mode 100644 dashboard.html create mode 100644 dashboard.php create mode 100644 db_config.php create mode 100644 export_books.php create mode 100644 export_books.py create mode 100644 index.css create mode 100644 index.html create mode 100644 index.php create mode 100644 login.css create mode 100644 login.html create mode 100644 login.php create mode 100644 logout.php create mode 100644 navbar.php create mode 100644 register.css create mode 100644 register.html create mode 100644 register.php create mode 100644 search.js create mode 100644 search_books.css create mode 100644 search_books.html create mode 100644 search_books.php create mode 100644 validation.js diff --git a/add_book.css b/add_book.css new file mode 100644 index 0000000..9b7131c --- /dev/null +++ b/add_book.css @@ -0,0 +1,95 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + background-color: #f4f4f4; /* Light grey background */ + color: #333; /* Dark text color */ + margin: 0; + padding: 0; +} + +header { + background-color: #2C3E50; /* Dark blue */ + color: white; + text-align: center; + padding: 20px 0; + margin-bottom: 40px; +} + +header h1 { + font-size: 2.5rem; + margin: 0; +} + +main { + padding: 40px 10px; + text-align: center; +} + +main h1 { + color: #2C3E50; /* Dark blue */ + font-size: 2.2rem; + margin-bottom: 20px; +} + +form { + background-color: #fff; + padding: 30px; + border-radius: 8px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + width: 50%; + margin: 0 auto; + box-sizing: border-box; + display: flex; + flex-direction: column; + align-items: center; /* Center the form elements */ +} + +.form-group { + width: 100%; /* Ensure form-group takes full width */ + margin-bottom: 15px; + display: flex; + flex-direction: column; + align-items: flex-start; +} + +form label { + font-size: 1rem; + margin-bottom: 5px; + width: 100%; /* Ensure label takes full width */ +} + +form input { + width: 100%; + padding: 12px; + font-size: 1rem; + margin-bottom: 15px; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; +} + +form button { + background-color: #2C3E50; /* Dark blue */ + color: white; + padding: 12px 20px; + border: none; + border-radius: 4px; + font-size: 1.2rem; + cursor: pointer; + transition: background-color 0.3s ease; + align-self: flex-start; /* Align button to the start */ +} + +form button:hover { + background-color: #1A252F; /* Darker blue on hover */ +} + +footer { + background-color: #2C3E50; /* Dark blue */ + color: white; + text-align: center; + padding: 10px; + position: absolute; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/add_book.html b/add_book.html new file mode 100644 index 0000000..7428fa2 --- /dev/null +++ b/add_book.html @@ -0,0 +1,44 @@ + + + + + + Add Book + + + + + + +
+

Add a New Book

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+ + + + \ No newline at end of file diff --git a/add_book.php b/add_book.php new file mode 100644 index 0000000..96226ca --- /dev/null +++ b/add_book.php @@ -0,0 +1,101 @@ +query($query); + $books = []; + + while ($row = $result->fetch_assoc()) { + $books[] = $row; + } + + // Save the books array to books.json + file_put_contents('books.json', json_encode($books, JSON_PRETTY_PRINT)); +} + +// Handle form submission +if ($_SERVER["REQUEST_METHOD"] === "POST") { + // Retrieve form data + $title = $_POST['title'] ?? ''; + $author = $_POST['author'] ?? ''; + $publication_year = $_POST['publication_year'] ?? 0; + $genre = $_POST['genre'] ?? ''; + + // Validate form data + if (empty($title) || empty($author) || empty($publication_year) || empty($genre)) { + echo ""; + exit; + } + + // Insert data into the database + $stmt = $conn->prepare("INSERT INTO books (title, author, publication_year, genre) VALUES (?, ?, ?, ?)"); + if (!$stmt) { + die("Prepare failed: " . $conn->error); + } + + $stmt->bind_param("ssis", $title, $author, $publication_year, $genre); + + if ($stmt->execute()) { + updateJsonFile($conn); // Update the JSON file after adding the book + echo ""; + exit; + } else { + die("Error adding book: " . $stmt->error); + } +} +?> + + + + + + + Add Book + + + + + + +
+

Add a New Book

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+
+ + + + \ No newline at end of file diff --git a/books.json b/books.json new file mode 100644 index 0000000..0b261a3 --- /dev/null +++ b/books.json @@ -0,0 +1,30 @@ +[ + { + "id": "4", + "title": "2nd", + "author": "Habilis", + "publication_year": "2002", + "genre": "Evolution" + }, + { + "id": "6", + "title": "feature", + "author": "second", + "publication_year": "2002", + "genre": "tested" + }, + { + "id": "8", + "title": "sample", + "author": "2nd", + "publication_year": "2002", + "genre": "tested" + }, + { + "id": "13", + "title": "BioInformatics: From Genomes to Drugs", + "author": " Ralf Hofest\u00e4dt", + "publication_year": "2002", + "genre": "Life" + } +] \ No newline at end of file diff --git a/books.xml b/books.xml new file mode 100644 index 0000000..92127d8 --- /dev/null +++ b/books.xml @@ -0,0 +1,2 @@ + +42ndHabilis2002Evolution6featuresecond2002tested8sample2nd2002tested13BioInformatics: From Genomes to Drugs Ralf Hofestädt2002LifeEvolution1tested2Life1 \ No newline at end of file diff --git a/common.css b/common.css new file mode 100644 index 0000000..515f84f --- /dev/null +++ b/common.css @@ -0,0 +1,48 @@ +body { + font-family: Arial, sans-serif; + margin: 0; + padding: 0; + background-color: #f4f4f9; +} + +header { + background-color: #333; + color: rgb(218, 0, 0); + padding: 1em; + text-align: center; +} + +form { + width: 50%; + margin: 2em auto; + padding: 2em; + background: white; + border: 1px solid #ccc; + border-radius: 8px; +} + +form label { + display: block; + margin: 0.5em 0 0.2em; +} + +form input { + width: 100%; + padding: 0.5em; + margin-bottom: 1em; + border: 1px solid #ccc; + border-radius: 4px; +} + +form button { + background-color: #333; + color: white; + padding: 0.7em 1.5em; + border: none; + border-radius: 4px; + cursor: pointer; +} + +form button:hover { + background-color: #555; +} \ No newline at end of file diff --git a/dashboard.css b/dashboard.css new file mode 100644 index 0000000..88ab59b --- /dev/null +++ b/dashboard.css @@ -0,0 +1,62 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + background-color: #f4f4f4; /* Light grey background */ + color: #333333; /* Dark text color */ + margin: 0; + padding: 0; +} + +header { + background-color: #2C3E50; /* Dark blue */ + color: #ffffff; /* White text */ + text-align: center; + padding: 20px 0; + margin-bottom: 40px; +} + +header h1 { + font-size: 2.5rem; + margin: 0; +} + +main { + text-align: center; + padding: 30px 10px; +} + +main h2 { + color: #2C3E50; /* Dark blue */ + font-size: 2rem; + margin-bottom: 30px; +} + +.actions { + display: flex; + justify-content: center; + gap: 20px; +} + +.actions a { + background-color: #3498db; /* Blue button */ + color: #ffffff; /* White text */ + padding: 12px 20px; + text-decoration: none; + border-radius: 4px; + font-size: 1.1rem; + transition: background-color 0.3s; +} + +.actions a:hover { + background-color: #2980b9; /* Darker blue on hover */ +} + +footer { + background-color: #2C3E50; /* Dark blue */ + color: #ffffff; /* White text */ + text-align: center; + padding: 10px; + position: absolute; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/dashboard.html b/dashboard.html new file mode 100644 index 0000000..f704f4e --- /dev/null +++ b/dashboard.html @@ -0,0 +1,23 @@ + + + + + + + Dashboard + + + + +
+

Welcome to the Dashboard

+ +
+ + + \ No newline at end of file diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..4589b42 --- /dev/null +++ b/dashboard.php @@ -0,0 +1,23 @@ + + + + + + + Dashboard + + + + +
+

Welcome to the Dashboard

+ +
+ + + \ No newline at end of file diff --git a/db_config.php b/db_config.php new file mode 100644 index 0000000..1f2191e --- /dev/null +++ b/db_config.php @@ -0,0 +1,16 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} +?> \ No newline at end of file diff --git a/export_books.php b/export_books.php new file mode 100644 index 0000000..1f6cbe4 --- /dev/null +++ b/export_books.php @@ -0,0 +1,15 @@ +&1"); // Ensure paths with spaces are handled properly + +// Check if the script executed successfully and output the results +if ($output) { + echo "Books and genre counts exported to books.xml successfully!"; +} else { + echo "Failed to export books to XML. Please check the server logs for more details."; +} +?> \ No newline at end of file diff --git a/export_books.py b/export_books.py new file mode 100644 index 0000000..e537d57 --- /dev/null +++ b/export_books.py @@ -0,0 +1,40 @@ +import json +import xml.etree.ElementTree as ET +import os +from collections import Counter + +# Ensure the books.json file exists and is populated +if os.path.exists('books.json'): + with open('books.json', 'r') as file: + books = json.load(file) + + # Create XML root element + root = ET.Element('Library') + + # Add book entries to XML + for book in books: + book_element = ET.SubElement(root, 'Book') + for key, value in book.items(): + child = ET.SubElement(book_element, key) + child.text = str(value) + + # Calculate genre counts + genres = [book['genre'] for book in books] + genre_counts = Counter(genres) + + # Add GenreCounts section to XML + genre_counts_element = ET.SubElement(root, 'GenreCounts') + for genre, count in genre_counts.items(): + genre_element = ET.SubElement(genre_counts_element, 'Genre') + name_element = ET.SubElement(genre_element, 'Name') + name_element.text = genre + count_element = ET.SubElement(genre_element, 'Count') + count_element.text = str(count) + + # Write the XML data to a file + tree = ET.ElementTree(root) + tree.write('books.xml', encoding='utf-8', xml_declaration=True) + print("Books and genre counts exported to books.xml") + +else: + print("Error: books.json not found.") diff --git a/index.css b/index.css new file mode 100644 index 0000000..a2d699a --- /dev/null +++ b/index.css @@ -0,0 +1,132 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + margin: 0; + padding: 0; + background-color: #f4f4f4; + color: #333; +} + +a { + text-decoration: none; + color: inherit; +} + +h1, h2 { + margin: 0; + font-weight: normal; +} + +/* Header Styles */ +header { + background-color: #0044cc; + color: white; + padding: 20px; + text-align: center; +} + +header h1 a { + font-size: 2.5rem; + color: #fff; +} + +/* Navigation Styles */ +nav { + margin-top: 20px; + background-color: #003366; + padding: 10px; +} + +.nav-menu { + list-style: none; + padding: 0; + display: flex; + justify-content: center; +} + +.nav-menu li { + margin: 0 20px; +} + +.nav-menu a { + color: white; + font-size: 1.1rem; +} + +.nav-menu a:hover { + color: #ffcc00; +} + +/* Main Content Styles */ +main { + padding: 40px 20px; + text-align: center; +} + +section { + background-color: white; + padding: 30px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + border-radius: 8px; + margin: 0 auto; + max-width: 800px; +} + +h2 { + color: #0044cc; + font-size: 2rem; + margin-bottom: 20px; +} + +p { + font-size: 1.2rem; + color: #1b1b1b; +} + +.actions { + margin-top: 20px; +} + +.btn { + background-color: #0044cc; + color: white; + padding: 10px 20px; + border-radius: 5px; + font-size: 1rem; + margin: 10px; +} + +.btn:hover { + background-color: #003366; +} + +/* Logged-in User Styles */ +.logged-in p { + font-size: 1.2rem; + color: #0044cc; +} + +.actions .btn { + background-color: #00cc44; +} + +.actions .btn:hover { + background-color: #008c29; +} + +/* Footer Styles */ +footer { + background-color: #003366; /* Dark blue background */ + color: #f8f9fa; /* Light gray text for better contrast */ + text-align: center; + padding: 10px; + position: absolute; + bottom: 0; + width: 100%; + font-size: 0.9rem; /* Slightly smaller font for subtlety */ +} + +footer p { + margin: 0; + color: #ffffff; /* White text for maximum contrast */ +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..e234fbe --- /dev/null +++ b/index.html @@ -0,0 +1,48 @@ + + + + + + + Library Management System + + + + +
+

Welcome to the Library Management System

+ +
+
+
+

Manage Your Books Efficiently

+ +

Welcome, ! Manage books, search the library, and more.

+ +

Register or Log In to manage books, search the library, and more!

+ + +
+
+ + + \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..144e09e --- /dev/null +++ b/index.php @@ -0,0 +1,44 @@ + + + + + + + + Library Management System + + + + + + +
+
+

Manage Your Books Efficiently

+

+ + Welcome back, ! Use the menu above to navigate. + + Register or Log In to manage books, search the library, and more! + +

+ + + +
+
+ + + diff --git a/login.css b/login.css new file mode 100644 index 0000000..c787786 --- /dev/null +++ b/login.css @@ -0,0 +1,92 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + background-color: #f7f7f7; + color: #333; + margin: 0; + padding: 0; +} + +header { + background-color: #0044cc; + color: white; + text-align: center; + padding: 20px 0; + margin-bottom: 40px; +} + +header h1 { + font-size: 2.5rem; + margin: 0; +} + +/* Form Styles */ +form { + background-color: white; + max-width: 400px; + margin: 0 auto; + padding: 20px; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); + border-radius: 8px; +} + +form h2 { + color: #0044cc; + text-align: center; + margin-bottom: 20px; +} + +label { + font-size: 1.1rem; + color: #555; + margin-bottom: 8px; + display: block; +} + +input { + width: 100%; + padding: 12px; + margin: 8px 0 20px 0; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; + font-size: 1rem; +} + +input[type="text"], input[type="password"] { + background-color: #f0f0f0; +} + +button { + background-color: #0044cc; + color: white; + padding: 12px 20px; + border: none; + border-radius: 4px; + font-size: 1.1rem; + width: 100%; + cursor: pointer; +} + +button:hover { + background-color: #003366; +} + +/* Error Message */ +.error { + font-size: 1rem; + color: #d9534f; + text-align: center; + margin-top: 10px; +} + +/* Footer Styles */ +footer { + background-color: #003366; + color: white; + text-align: center; + padding: 10px; + position: absolute; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/login.html b/login.html new file mode 100644 index 0000000..3c25d55 --- /dev/null +++ b/login.html @@ -0,0 +1,27 @@ + + + + + + + + User Login + + + + +
+

Library Management System

+
+
+

Login

+ +
+ + +
+ + +
+ + diff --git a/login.php b/login.php new file mode 100644 index 0000000..3849903 --- /dev/null +++ b/login.php @@ -0,0 +1,25 @@ +prepare("SELECT * FROM users WHERE email = ? OR username = ?"); + $stmt->bind_param("ss", $username_email, $username_email); + $stmt->execute(); + $result = $stmt->get_result(); + $user = $result->fetch_assoc(); + + if ($user && password_verify($password, $user['password'])) { + $_SESSION['user_id'] = $user['id']; + $_SESSION['username'] = $user['username']; // Set username in session + header("Location: dashboard.php"); + exit; + } else { + echo "Invalid credentials. Try again"; + } +} +?> \ No newline at end of file diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..b9091dc --- /dev/null +++ b/logout.php @@ -0,0 +1,15 @@ + + alert('$username logged out successfully!'); + window.location.href = 'index.php'; + "; +} else { + header("Location: index.php"); + exit; +} +?> diff --git a/navbar.php b/navbar.php new file mode 100644 index 0000000..dce3238 --- /dev/null +++ b/navbar.php @@ -0,0 +1,115 @@ + + + + \ No newline at end of file diff --git a/register.css b/register.css new file mode 100644 index 0000000..ad0263b --- /dev/null +++ b/register.css @@ -0,0 +1,99 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + background-color: #f7f7f7; + color: #333; + margin: 0; + padding: 0; +} + +header { + background-color: #0044cc; + color: white; + text-align: center; + padding: 20px 0; + margin-bottom: 40px; +} + +header h1 { + font-size: 2.5rem; + margin: 0; +} + +/* Form Styles */ +form { + background-color: white; + max-width: 400px; + margin: 0 auto; + padding: 20px; + box-shadow: 0 0 15px rgba(0, 0, 0, 0.1); + border-radius: 8px; +} + +form h2 { + color: #0044cc; + text-align: center; + margin-bottom: 20px; +} + +label { + font-size: 1.1rem; + color: #555; + margin-bottom: 8px; + display: block; +} + +input { + width: 100%; + padding: 12px; + margin: 8px 0 20px 0; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; + font-size: 1rem; +} + +input[type="text"], input[type="email"], input[type="password"] { + background-color: #f0f0f0; +} + +button { + background-color: #0044cc; + color: white; + padding: 12px 20px; + border: none; + border-radius: 4px; + font-size: 1.1rem; + width: 100%; + cursor: pointer; +} + +button:hover { + background-color: #003366; +} + +/* Error/Success Messages */ +.success, .error { + font-size: 1rem; + text-align: center; + margin-top: 10px; +} + +.success { + color: #5bc0de; +} + +.error { + color: #d9534f; +} + +/* Footer Styles */ +footer { + background-color: #003366; + color: white; + text-align: center; + padding: 10px; + position: absolute; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/register.html b/register.html new file mode 100644 index 0000000..0940c38 --- /dev/null +++ b/register.html @@ -0,0 +1,28 @@ + + + + + + User Registration + + + + +
+

Library Management System

+
+
+

Register

+ +
+ + +
+ + +
+ + +
+ + \ No newline at end of file diff --git a/register.php b/register.php new file mode 100644 index 0000000..07ffeae --- /dev/null +++ b/register.php @@ -0,0 +1,30 @@ +prepare("SELECT * FROM users WHERE email = ?"); + $checkQuery->bind_param("s", $email); + $checkQuery->execute(); + $result = $checkQuery->get_result(); + + if ($result->num_rows > 0) { + echo "
Email already exists! Go back
"; + exit; + } + + // Insert user into the database + $stmt = $conn->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)"); + $stmt->bind_param("sss", $username, $email, $password); + + if ($stmt->execute()) { + echo "
Registration successful! Login here
"; + } else { + echo "
Error registering user. Please try again.
"; + } +} +?> \ No newline at end of file diff --git a/search.js b/search.js new file mode 100644 index 0000000..b2ae60a --- /dev/null +++ b/search.js @@ -0,0 +1,34 @@ +document.getElementById("searchBookForm").addEventListener("submit", async function (e) { + e.preventDefault(); + const title = document.getElementById("search_title").value.trim(); + const author = document.getElementById("search_author").value.trim(); + const year = document.getElementById("search_year").value.trim(); + + // Fetch search results using PHP backend + const response = await fetch("search_books.php", { + method: "POST", + headers: { "Content-Type": "application/x-www-form-urlencoded" }, + body: new URLSearchParams({ title, author, year }), + }); + const books = await response.json(); + + const tableBody = document.getElementById("results").querySelector("tbody"); + tableBody.innerHTML = ""; // Clear previous results + + books.forEach(book => { + const row = ` + ${book.id} + ${book.title} + ${book.author} + ${book.publication_year} + ${book.genre} + `; + tableBody.innerHTML += row; + }); +}); + +// Export to XML handler +document.getElementById("exportXML").addEventListener("click", async function () { + await fetch("export_books.php"); + alert("Books exported to XML!"); +}); diff --git a/search_books.css b/search_books.css new file mode 100644 index 0000000..77a82e7 --- /dev/null +++ b/search_books.css @@ -0,0 +1,131 @@ +/* General Styles */ +body { + font-family: 'Cambria', serif; + background-color: #f8f9fa; /* Light neutral background */ + color: #333; + margin: 0; + padding: 0; +} + +/* Header */ +header { + background-color: #008080; /* Teal color */ + color: white; + text-align: center; + padding: 20px 0; + margin-bottom: 40px; +} + +header h1 { + font-size: 2.5rem; + margin: 0; +} + +/* Main Section */ +main { + padding: 20px 10px; + display: flex; + flex-direction: column; + align-items: center; +} + +main h1 { + color: #008080; + font-size: 2.2rem; + margin-bottom: 20px; +} + +/* Form Styles */ +form { + background-color: #ffffff; /* White form background */ + padding: 30px; + border-radius: 10px; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); /* Subtle shadow */ + width: 50%; /* Fixed width for the form */ + max-width: 600px; /* Ensure responsiveness */ + display: flex; + flex-direction: column; + align-items: center; + box-sizing: border-box; +} + +form label { + font-size: 1rem; + font-weight: 500; + color: #555; + margin-bottom: 5px; + align-self: flex-start; /* Align labels to the left */ +} + +form input { + width: 100%; + padding: 12px; + font-size: 1rem; + border: 1px solid #ced4da; /* Light gray border */ + border-radius: 5px; + margin-bottom: 15px; + background-color: #f8f9fa; /* Light background for inputs */ + transition: border-color 0.3s; +} + +form input:focus { + outline: none; + border-color: #008080; /* Highlight input on focus */ +} + +form button { + background-color: #008080; + color: white; + padding: 10px 20px; + border: none; + border-radius: 5px; + font-size: 1rem; + cursor: pointer; + transition: background-color 0.3s ease; + margin: 5px; +} + +form button:hover { + background-color: #006666; /* Slightly darker teal on hover */ +} + +/* Table Styles */ +table { + width: 80%; + margin: 30px auto 0 auto; + border-collapse: collapse; + box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05); /* Subtle shadow */ +} + +table th, table td { + border: 1px solid #dee2e6; /* Light border */ + padding: 12px; + text-align: center; + font-size: 0.9rem; +} + +table th { + background-color: #008080; /* Teal for headers */ + color: white; + font-weight: 600; +} + +table tr:nth-child(even) { + background-color: #f8f9fa; /* Alternating row background */ +} + +table tr:hover { + background-color: #e9ecef; /* Highlight row on hover */ +} + +/* Footer */ +footer { + background-color: #008080; + color: white; + text-align: center; + padding: 10px; + margin-top: 30px; + position: relative; + bottom: 0; + width: 100%; +} \ No newline at end of file diff --git a/search_books.html b/search_books.html new file mode 100644 index 0000000..ae2b2a5 --- /dev/null +++ b/search_books.html @@ -0,0 +1,103 @@ + + + + + + Search Books + + + + + + +
+

Search Books

+ +
+ +
+ + +
+ + +
+ + + +
+ +

Search Results:

+ + + + + + + + + + + + +
TitleAuthorPublication YearGenre
+
+ + + + + + \ No newline at end of file diff --git a/search_books.php b/search_books.php new file mode 100644 index 0000000..98e2d9d --- /dev/null +++ b/search_books.php @@ -0,0 +1,41 @@ +real_escape_string($title) . "%'"; + } + if ($author) { + $query .= " AND author LIKE '%" . $conn->real_escape_string($author) . "%'"; + } + if ($publication_year) { + $query .= " AND publication_year = " . (int)$publication_year; + } + + $search_results = $conn->query($query); + $books = []; + + if ($search_results && $search_results->num_rows > 0) { + while ($row = $search_results->fetch_assoc()) { + $books[] = $row; + } + file_put_contents('books.json', json_encode($books, JSON_PRETTY_PRINT)); + } + + header('Content-Type: application/json'); + echo json_encode($books); + exit; +} \ No newline at end of file diff --git a/validation.js b/validation.js new file mode 100644 index 0000000..1f36f84 --- /dev/null +++ b/validation.js @@ -0,0 +1,13 @@ +document.getElementById("addBookForm").addEventListener("submit", function (e) { + const title = document.getElementById("title").value.trim(); + const author = document.getElementById("author").value.trim(); + const publicationYear = parseInt(document.getElementById("publication_year").value); + const genre = document.getElementById("genre").value.trim(); + + if (!title || !author || !genre || isNaN(publicationYear) || publicationYear <= 2000) { + e.preventDefault(); + alert("All fields are required, and the publication year must be greater than 2000."); + } else { + alert("Book successfully added!"); + } +});