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.
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.
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.
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.
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.
- Open phpMyAdmin at http://phpmyadmin.test (macOS) or http://localhost/phpmyadmin (Windows)
- Log in to phpMyAdmin using the root username and password
- From the phpMyAdmin homepage, click on the "Import" tab found at the top of the page.
- Under the "File to import" section, click the "Choose File" button. Choose the
seussology.sql
file found in this repository. - Click the "Go" button found at the bottom of the page.
- Once the importing has been completed, click on the Seussology database, which should appear in the list on the left side of the page.
- 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 Name | Data Type | Default Value | Required |
---|---|---|---|
book_id | integer | None | yes |
book_title | string | None | yes |
book_title_sort | string | NULL | no |
book_year | 4 digit year | NULL | no |
book_description | string | NULL | no |
book_pages | integer | NULL | no |
book_image | string | NULL | no |
category_id | integer | NULL | no |
categories
Column Name | Data Type | Default Value | Required |
---|---|---|---|
category_id | integer | None | yes |
category_name | string | None | yes |
quotes
Column Name | Data Type | Default Value | Required |
---|---|---|---|
quote_id | integer | None | yes |
quote | string | None | yes |
book_id | integer | None | yes |
Requirements
The following requirements must be met to complete the assignment successfully:
- 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.
- 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.
- 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.
- 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.
- On the book's edit page, a delete button should allow the user to delete the current book.
- 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.
- For added security, prepared statements should be used any time a user provides data for a database query.
- 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 asfalse
. - 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 beNULL
. - The
book_year
must be a 4 digit number. - The
book_pages
must be a number. - Provide a data type on the bindValue() function to pass a value other than a string.
Example
You can find a completed version below: