Lab 9 - PHP and MySQL
Lab 9 - PHP and MySQL
Due Date
• This lab must be handed in:
Friday Nov 22, 2024 – before midnight
Assessment
• This Lab is worth 3% of your total course mark.
Assigned Readings
➢ Lecture Slides posted on Brightspace
• Module 4 -> Part 2
➢ The following chapters of Fundamentals of Web Development will be useful in
completing this exercise:
• Chapter 11
Lab Supplies
To complete this lab you will require the following lab supplies:
• Lecture Slides (Module 4 -> Part 2) and Code Examples (CRUD Example-EasyPHP.zip)
posted on Brightspace
• Textbook: Fundamentals of Web Development by Randy Connolly and Ricardo Hoar
• EasyPHP, or other WAMP server
• Eclipse, Notepad++ (or other text editor, or IDE)
Summary of Tasks
1. Gather MySQL Information
2. Understanding your database
3. Develop the logic to display your web application
4. View your webpage using a web browser
5. Submit Source Code of all PHP files on Brightspace
Task 1
Before we can get started using MySQL on the web hosting server we need a few pieces of
information.
• Host
o The host variable should contain the value “localhost”.
o Example: $host = “localhost”;
o NOTE: Localhost is a networking term meaning ‘this computer’
• Username
o The Username to access YOUR database MUST be as below:
$username = "cst8238";
• Password
o The password to access YOUR database MUST be as below:
$password = "cst@8238";
• Database Name
o The name of your database MUST be as below:
$database ="cst8238";
Task 2
To create your database, username, password and tables on the EasyPHP Web server, please
review the following document on Brightspace:
Course Content -> Module 4 – Dynamic Web Programming -> Part 2- PHP and MySQL ->
CRUD Example-EasyPHP.zip -> CRUD_PDO-EasyPHP -> Instruction_MySQL_EasyPHP.docx
Task 3
Now that we have a database we have to understand the tables inside it. Your database must
contain a table named Employee.
❖ NOTE
➢ EmployeeId is listed as ‘AUTO INCREMENT’ meaning that the database will
automatically populate this field.
➢ You MUST access the DB using PDO (PHP Data Object) as below:
$pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Implement the following Design Pattern to create a ‘Common Look and Feel’ to be used on
every page of your website.
Header.php must contain a script to display a Common Header that will appear on every page.
The header must display Program Name and Course Name
Footer.php
Footer.php must contain a script to display a Common Footer that will appear on every page.
The footer must contain Student Number, First Name, Last Name, and Email Address
Menu.php
Menu.php must contain a script to display a Common Menu to be shown on every page. The
menu must contain links to CreateAccount.php, Login.php and ViewAllEmployees.php.
CreateAccount.php
Create a form that will create employee accounts in the ‘Employee’ table of your database.
Details:
1. Use ‘input’ tags to accept the information listed in Task 3. Your form must populate all
the columns of the ‘Employee’ table.
2. After the information has been submitted to the database, save each of the values from
the form in the Session State.
3. Once the employee data is stored in the Session, automatically redirect the user to
‘ViewAllEmployees.php’
NOTE: EmployeeId is listed as ‘AUTO INCREMENT’ meaning that the database will
automatically populate this field.
The form Login.php allows the user to log into your application.
Details:
1. Create a form to accept the employees’s EmailAddress and Password as credentials to
your site. Use an SQL Query to determine if the person has an account.
2. If the user has an account, store ALL of their personal information in the Session State
and then redirect the user to ‘ViewAllEmployees.php’. Display an error if the user cannot
log into the system.
ViewAllEmployees.php
This page pulls information from both the Session and the Database and displays the information
to the user.
Details:
1. If the employee tries to navigate to this page without having logged in – the employee
should be redirected to the login page.
2. If the employee has successfully logged into the application and is directed to the page,
then display the following information
a. Divide the content of the page into 2 sections (One on top of the other)
b. The top section of the page will display all details of the employee stored in the
Session State
c. The bottom section of the page will display a HTML table containing all rows
and columns of the ‘Employee’ table of your database. The HTML table must
also contain a header row that identifies the column name of the database table.
d. Provide H1 HTML headers so that both sections (Session State Data and
Database Data) are clearly marked
Sample Screenshot for ViewAllEmployees.php is as follows:
NOTE: To verify that an employee has successfully logged in, check for valid information in the
Session State. If the Session State does not contain valid information redirect to the login page,
otherwise, the user has logged in successfully.
NOTE: All the sample screenshots must include common header, footer and menu files.
Task 4
Create Lab 9 submission folder ‘Lab9’ and copy CreateAccount.php, Login.php,
ViewAllEmployees.php, Header.php, Footer.php, Menu.php and any other required files (e.g.
css file) into this folder.
Task 5
Create a compressed file (Lab9.zip) which will contain the following PHP files:
• Header.php, Footer.php, Menu.php
• CreateAccount.php
• Login.php
• ViewAllEmployees.php
• any other required files (e.g. css file)
(N.B. Please keep in mind that ONLY .zip file is accepted as the format of the compressed file.)
To hand in your lab go to Brightspace and navigate to Content → Labs and click on ‘Lab 9 – PHP
and MySQL’ link.
Finally, click the ‘Submit’ button to send the lab to your professor.