B - Search Criteria

Create a webpage that allows the user to search for books via a title.

CREATE DATABASE Books;

USE Books;

CREATE TABLE Books (
    id INT PRIMARY KEY,
    title VARCHAR(100),
    author VARCHAR(100),
    genre VARCHAR(50),
    publication_date DATE
);
INSERT INTO Books (id, title, author, genre, publication_date) VALUES
(1, 'Harry Potter and the Philosophers Stone', 'J.K. Rowling', 'Fantasy', '1997-06-26'),
(2, 'The Hobbit', 'J.R.R. Tolkien', 'Fantasy', '1937-09-21'),
(3, 'The Lord of the Rings', 'J.R.R. Tolkien', 'Fantasy', '1954-07-29'),
(4, 'The Hunger Games', 'Suzanne Collins', 'Dystopian', '2008-09-14'),
(5, 'Catching Fire', 'Suzanne Collins', 'Dystopian', '2009-09-01'),
(6, 'Mockingjay', 'Suzanne Collins', 'Dystopian', '2010-08-24'),
(7, 'The Lion the Witch and the Wardrobe', 'C.S. Lewis', 'Fantasy', '1950-10-16'),
(8, 'The Little Prince', 'Antoine de Saint Exupery', 'Fantasy', '1943-04-06'),
(9, 'Alice in Wonderland', 'Lewis Carroll', 'Fantasy', '1865-11-26'),
(10, 'The Secret Garden', 'Frances Hodgson Burnett', 'Classic', '1911-08-01'),
(11, 'Charlie and the Chocolate Factory', 'Roald Dahl', 'Fantasy', '1964-01-01'),
(12, 'Matilda', 'Roald Dahl', 'Fantasy', '1988-10-01'),
(13, 'The BFG', 'Roald Dahl', 'Fantasy', '1982-01-01'),
(14, 'Fantastic Mr Fox', 'Roald Dahl', 'Fantasy', '1970-01-01'),
(15, 'George Marvellous Medicine', 'Roald Dahl', 'Fantasy', '1981-01-01'),
(16, 'The Twits', 'Roald Dahl', 'Comedy', '1980-01-01'),
(17, 'Wonder', 'R.J. Palacio', 'Drama', '2012-02-14'),
(18, 'The Fault in Our Stars', 'John Green', 'Romance', '2012-01-10'),
(19, 'Paper Towns', 'John Green', 'Mystery', '2008-10-16'),
(20, 'Looking for Alaska', 'John Green', 'Drama', '2005-03-03'),
(21, 'The Maze Runner', 'James Dashner', 'Science Fiction', '2009-10-06'),
(22, 'The Scorch Trials', 'James Dashner', 'Science Fiction', '2010-09-18'),
(23, 'The Death Cure', 'James Dashner', 'Science Fiction', '2011-10-11'),
(24, 'Percy Jackson and the Lightning Thief', 'Rick Riordan', 'Fantasy', '2005-06-28'),
(25, 'Percy Jackson and the Sea of Monsters', 'Rick Riordan', 'Fantasy', '2006-04-01'),
(26, 'The Titans Curse', 'Rick Riordan', 'Fantasy', '2007-05-01'),
(27, 'The Last Olympian', 'Rick Riordan', 'Fantasy', '2009-05-05'),
(28, 'Diary of a Wimpy Kid', 'Jeff Kinney', 'Comedy', '2007-04-01'),
(29, 'Rodrick Rules', 'Jeff Kinney', 'Comedy', '2008-02-01'),
(30, 'The Last Straw', 'Jeff Kinney', 'Comedy', '2009-01-01'),
(31, 'The Hitchhikers Guide to the Galaxy', 'Douglas Adams', 'Science Fiction', '1979-10-12'),
(32, 'The Time Machine', 'H.G. Wells', 'Science Fiction', '1895-05-07'),
(33, 'The War of the Worlds', 'H.G. Wells', 'Science Fiction', '1898-01-01'),
(34, 'The Invisible Man', 'H.G. Wells', 'Science Fiction', '1897-01-01'),
(35, 'The Great Gatsby', 'F. Scott Fitzgerald', 'Classic', '1925-04-10'),
(36, 'To Kill a Mockingbird', 'Harper Lee', 'Drama', '1960-07-11'),
(37, 'Of Mice and Men', 'John Steinbeck', 'Drama', '1937-02-06'),
(38, 'Animal Farm', 'George Orwell', 'Political Fiction', '1945-08-17'),
(39, 'Nineteen Eighty Four', 'George Orwell', 'Dystopian', '1949-06-08'),
(40, 'The Book Thief', 'Markus Zusak', 'Historical', '2005-03-14'),
(41, 'The Alchemist', 'Paulo Coelho', 'Adventure', '1988-01-01'),
(42, 'The Da Vinci Code', 'Dan Brown', 'Mystery', '2003-04-01'),
(43, 'Angels and Demons', 'Dan Brown', 'Mystery', '2000-05-01'),
(44, 'The Girl with the Dragon Tattoo', 'Stieg Larsson', 'Mystery', '2005-08-01'),
(45, 'The Adventures of Sherlock Holmes', 'Arthur Conan Doyle', 'Mystery', '1892-10-14'),
(46, 'The Call of the Wild', 'Jack London', 'Adventure', '1903-01-01'),
(47, 'Treasure Island', 'Robert Louis Stevenson', 'Adventure', '1883-11-14'),
(48, 'The Jungle Book', 'Rudyard Kipling', 'Adventure', '1894-01-01'),
(49, 'A Christmas Carol', 'Charles Dickens', 'Classic', '1843-12-19'),
(50, 'Oliver Twist', 'Charles Dickens', 'Classic', '1838-01-01');
$title = $_POST["title"];
        
$sql = "SELECT * FROM books where title like '%$title%'";

Extension

Try using different form inputs

  • Select
  • Radio