Overview
For this lab you will practice PHP and MySQLi workflow by creating search & search results pages for Football Schedule DB.
Sample
Note: samples below don’t always meet all the requirements. Make sure to follow the requirements rather than solely relying on the samples.
http://304.itpwebdev.com/~zune/lab_06/search_form.php
Requirements
Part 1 – Football Schedule Database Import
- Download football_schedule.sql file.
- Create a new database in cPanel → MySQL Databases.
- Name it
username_football_schedule_db
(cPanel will prefix your username for you automatically). - Add the database user created in class to your Football Schedule database.
- cPanel → MySQL Databases → Add User To Database → Select your user & database then press “Add” → Check All Privileges → Make Changes.
- Name it
- Import
football_schedule.sql
tofootball_schedule_db
.- cPanel → PHPMyAdmin → [Click on username_dvd_db Database] → Import.
- Verify all tables exist and are populated with data using phpMyAdmin.
- All tables and relationships should match the figures below. You don’t need to create this diagram. Simply use phpMyAdmin to ensure that all tables look like the tables below.Football Schedule Database
Part 2 – PHP MySQLi
- Download starter file: lab09/
- Starter files have comment blocks and ‘TODO’ as hints. You only need to add code in those sections.
- Search Form (
search_form.php
):- All three (3) drop-downs need to be dynamically populated.
- Do not hard-code dropdown options.
- The form submits to
search_results.php
usingGET
method. - On top of the file:
-
- Establish database connection (create
mysqli
object). - Check and output any DB connection errors.
- For each dropdown (team, venue, day):
- Create a SQL statement to get all columns and rows from those tables,
- Submit SQL statement to the DB (query the DB),
- Check and output any SQL errors.
- Close MySQLi connection.
- Establish database connection (create
-
- For each drop-down in HTML section (team, venue, day):
- Loop through corresponding results,
- Output
<option>
tags withvalue
attribute set to primary key and set option (text visible to users) as team, venue, or days.
- All three (3) drop-downs need to be dynamically populated.
- Search Results (
search_results.php
):- Output search results based on user criteria from search form.
- Show 5 columns:
- Date,
- Day (name, not ID),
- Home Team (name, not ID),
- Away Team (name, not ID),
- Venue (name, not ID)
- On top of the file:
- Establish database connection (create
mysqli
object). - Check and output any DB connection errors.
- Create a SQL statement that will retrieve all necessary columns and rows for output.
- Hints:
- Start with showing ALL records first, without adding any search criteria.
- You can alias table names in JOIN statements — useful for joining the same table multiple times
- Once the search works, you can go back and add search criteria one by one.
- Hints:
- Submit SQL statement to the DB (query the DB).
- Check and output any SQL errors.
- Close MySQLi connection.
- Establish database connection (create
- For the table in the HTML section:
- Loop through and output the results row by row.
- Submission:
- When completed, you will need to upload this page to the itpwebdev server via FileZilla (like you have done for labs/assignments earlier in the semester).
- Connect to the itpwebdev server on FileZilla. Create a folder named
lab09
and upload all files to this folder. - In your browser, go to
http://303.itpwebdev.com/~yourusername/lab09/search_form.php
to check that the assignment file has been uploaded correctly. - One last thing. In your computer, open up
student_page.html
that you created in Lab 1. Add a link to this assignment tostudent_page.html
under the heading “Labs” so that the TAs can easily access your completed assignment. - Upload the updated
student_page.html
to the itpwebdev server via FileZilla inside thepublic_html
folder. If it asks you want to overwrite the previous file, click Yes.