Page 1 of 3
CIS 12
Lab 9
For this lab, we are going to borrow some items from previous labs, lab 3 and lab 5 specifically.
If you have done those already, wonderful, your job is a bit easier. If not, never fear, I have
included those files for you to download from my website and from the school’s networked “I”
drive.
You will be altering the files that are given and you will be creating new files to add to the
website. In this lab, we will be merging everything I have been lecturing from the first week until
now.
For years, PHP developers have used the standard MySQL extensions for connecting to a
database. As of PHP 5 and MySQL 4.1, you can use the newer and improved extensions, which
is what this lab covers. I know that the school’s setup covers this. If you want to use your home
set up, you must have PHP 5.6 and MYSQL 5 installed to complete this lab.
Part 1 - Create the database
This step is only necessary if you didn’t complete lab 5, or if you deleted lab 5 for some reason.
If you completed lab 5, simply select the sitename database in the GUI or type use sitename;
as a query inside of SQL server command line.
1. Turn on XAMPP and MySQL Server
2. Download the Chapter_05_database.txt file, either from my website or from the I drive, and
cut and paste the contents into the SQL query box under the SQL tab in PHPMyAdmin GUI.
(Feel free to use the command line or the MySQL workbench, if you wish.)
3. Confirm the existence of the tables, and the data in the tables.
Part 2 - The Core Files (The Template)
1. Download the following files from the I drive or from my website: index.php, header.html,
footer.html, and style.css.
2. Create a folder called Ch09 in the htdocs folder.
3. Create a folder called includes in the Ch09 folder.
4. Copy the following files (index.php, header.html, footer.html, style.css) using the same
hierarchy as you did in Lab 3:
htdocs >> Ch09 >> index.php >> includes >> header.html >> footer.html >> style.css
5. Using a browser, browse to http://localhost/Ch09/index.php and verify that the website works
the same way as it did in lab 3.
Part 3 - Modifying the Template Pg. 266
1. Follow steps 1-5 on page 266 and 267.
Page 2 of 3
Part 4 - Connecting to MySQL Pg. 268
We will now connect the database to your PHP website. We do this by creating a brand-new file
called my_sqli_connect.php.
1. Follow steps 1-5 on pages 268 - 270. I am modifying these steps slightly.
2. On step 2, instead of typing ‘username’ instead type ‘root’. Instead of ‘password’, use the
empty string (‘’). Leave everything else the same. If you are using a system at home, and
you have changed the XAMPP installation to a different password, then use the settings you
changed it to. If you just installed it, and didn’t change the root user, then use my settings.
3. On step 5, instead of placing the file outside of the htdocs folder, place it inside the htdocs
folder next to Ch09 folder. Don’t put this file inside the Ch09 folder.
4. It is imperative that you name the file, just as it says in the book on step 4. If you don’t do
that correctly, this won’t work for you.
5. Complete Step 6 on page 271. (Open your browser and verify that the script works by going
to http://localhost/mysqli_connect.php. If you get a blank file, it works! If you get an error
message then verify that you did parts 1 - 3 correctly.)
Part 5 - Executing Simple Queries Pg. 273
1. Follow steps 1-15 on pages 274 - 280 to create register.php (script 9.3). Save this in the
Ch09 folder.
Part 6 - Retrieving Query Results Pg. 281
1. Follow steps 1-8 on pages 274 - 280 to create view_users.php (script 9.4). Save this in the
Ch09 folder.
2. Test the website and ensure that it works and the database can be viewed under the view
tab. Screenshot the view users tab.
Part 7 - Ensuring Secure SQL Pg. 285
This creates a secure SQL connection to the database.
1. Follow steps 1-5 on pages 286 - 280 to modify register.php (script 9.3)
2. Test the form. Try to add a few users with this form. Also add my name (Ian Lasky), email
(ian.lasky@rcc.edu), and password (12345) to the database using this form.
3. Screenshot the view users tab to show that you added the users
Part 8 - Counting Returned Records Pg. 286
Now we are going to modify the view_users.php file to count the total number of users.
1. Follow steps 1-6 on Pg. 290 - 291 to modify view_users.php (script 9.4).
2. Test the website and ensure that it works and the database can be viewed under the view
tab. Screenshot the view users tab.
Page 3 of 3
Part 9 - Updating Records with PHP Pg. 292
1. Follow steps 1-15 Pg. 292 - 297 to create password.php (script 9.7).
2. Test the form. Try to change the password for user ian.lasky@rcc.edu to 67890.
3. Screenshot the update records form.
Download PDF
Similar pages