Seussology

Objective

For this assignment, you will use what you have learned about PHP, MySQL, and PDO to create a database-driven book catalogue based on the Seussology database.

The site will have the following pages:

NOTE

Your site does not need to look like the one in the screenshots.

Homepage

The homepage should display all of the books in the databases. Just the book image should be displayed. If no book image is available, the book title should be displayed instead.

A search box should allow users to filter the books. The search form should submit to the homepage. Only those books that contain the search query in their title or description should be displayed.

A screenshot of the Seussology Homepage

Book Details Page

Click on any book from the homepage should take the user to that book's details page. The details page should include the book's title, image, description, published year, number of pages (if available), and book quotes (if any).

NOTE

Anytime you receive data from the user, it is best to use prepared statements.

NOTE

The book quotes are in the quotes tables.

The details page should also include a link to edit the current book.

A screenshot of the Seussology Details page

Edit Book Page

The edit book page should contain a form, pre-filled, that will allow the user to edit the book's details. The user should be allowed to edit the book's title, sort title, image, description, published year, and the number of pages. Submitting the form should update the book's details and return the user to the book details page.

NOTE

Anytime you receive data from the user, it is best to use prepared statements.

NOTE

The book_title, book_year, and book_description are required fields in the database and should not be left blank.

A delete button should also be available on the Edit Book Page, which will allow the user to delete a book from the database.

NOTE

The delete button should be part of a separate form, which will submit to a separate PHP file.

NOTE

It may be necessary to delete all the quotes related to the book before deleting the book itself.

A screenshot of the Seussology Edit page

New Book Page

The new book page should contain a form that will allow the user to add a new book to the database. The new book should include a book title, book sort title, published year, the number of pages, and a description. When the user submits the form, the database should be updated, and the user should be taken to the new book's details page.

NOTE

Anytime you receive data from the user, it is best to use prepared statements.

NOTE

The book_title, book_year, and book_description are required fields in the database and should not be left blank.

A screenshot of the Seussology New book page

Project Setup

1. Clone the Repository

Clone this repository from GitHub and use the provided files to complete the assignment.

2. Import the Seussology Database

To import the database, using phpMyAdmin, complete the following instructions.

  1. Open phpMyAdmin at http://phpmyadmin.testopen in new window (macOS) or http://localhost/phpmyadminopen in new window (Windows)
  2. Log in to phpMyAdmin using the root username and password
  3. From the phpMyAdmin homepage, click on the "Import" tab found at the top of the page.
  4. Under the "File to import" section, click the "Choose File" button. Choose the seussology.sql file found in this repository.
  5. Click the "Go" button found at the bottom of the page.
  6. Once the importing has been completed, click on the Seussology database, which should appear in the list on the left side of the page.
  7. With the Seussology database selected, click on the "SQL" tab at the top of the page. From this page, you can execute custom SQL commands.

The following shows the structure of the Seussology tables and the column names, required data types, default values, and which columns are required.

books

Column NameData TypeDefault ValueRequired
book_idintegerNoneyes
book_titlestringNoneyes
book_title_sortstringNULLno
book_year4 digit yearNULLno
book_descriptionstringNULLno
book_pagesintegerNULLno
book_imagestringNULLno
category_idintegerNULLno

categories

Column NameData TypeDefault ValueRequired
category_idintegerNoneyes
category_namestringNoneyes

quotes

Column NameData TypeDefault ValueRequired
quote_idintegerNoneyes
quotestringNoneyes
book_idintegerNoneyes

Requirements

The following requirements must be met to complete the assignment successfully:

  1. All books must be displayed on the homepage. Books with book covers should display the cover image, and books without book covers should display the book title. Clicking on either the book image or the book title should take the user to the book's details page.
  2. On the homepage, the user should be able to filter the books using a search box. All books whose title and/or description contains the search term should be displayed.
  3. The book's details page should include the book's cover image, the book's title, the book's description, the book's number of pages, and the quotes associated with the book. There should be an "edit" button on the book's details page, which will take the user to the book's edit page.
  4. The book's edit page should contain a pre-populated form of the book's details. Submitting the form should update the book's details.
  5. On the book's edit page, a delete button should allow the user to delete the current book.
  6. A new book page should contain a form to allow the user to enter new book data. Submitting the form should add a new book.
  7. For added security, prepared statements should be used any time a user provides data for a database query.
  8. The web application should have an appealing and intuitive interface.

Hints

  • If a book does not have an image in the database, it will have a NULL value. This is the same as false.
  • When performing a search on book titles and descriptions, it is best to use the LIKE clause.
  • Passing the book_id as a URL variable can be an effective way to specify a specific book.
  • It may be necessary to use two queries to retrieve the book's details and the book's quotes.
  • Each quote in the quotes table has a book_id that matches the respective book.
  • A form's input can be pre-filled by echoing out a PHP value directly into the value attribute.
  • The book_title cannot be NULL.
  • The book_year must be a 4 digit number.
  • The book_pages must be a number.
  • Provide a data type on the bindValue()open in new window function to pass a value other than a string.

Example

You can find a completed version below:

https://mtm6405-seussology.herokuapp.comopen in new window