Introduction to PHP and mySQL*

Due November 15

Part 1 - Introduction
Part 2 - Setting Up The Database
Part 3 - Inserting Information
Part 4 - Displaying Data
Part 5 - More Outputs
Part 6 - Single Records & Error Trapping
Part 7 - Updating & Deleting
Part 8 - Finishing The Script

Lab 6

This lab is an exploration into how to use the scripting language PHP with SQL. It assumes completion of the PHP and SQL exercises in this course. It also assumes at least a basic programming background such as Computer Science I at MVNU.

What to do, and what to hand in

Complete ALL the steps in this lab, using the CS server. If you have problems, PLEASE wee the instructor for help.

After you complete all steps, create a documetn and answer the following questions:

  1. What did you learn from the lab?
  2. What problems did you encounter, and how did you solve them?
  3. Is this an appropriate way to learn PHP/SQL, or would a more traditional classroom lecture/demonstration be better?
  4. What suggestions do you have for making the lab better?
  5. What is the link to your work (clickable web link)
Turn in this writeup to moodle.

Lets get started!

PHP is a scripting language that allows us to easily build a Web based application that interadts with a Database. Earlier we did some simple PHP, and I urge you to review what was learned there is you are having trouble. Also, use the course PHP text book as needed for reference.

You only really need three things to run PHP scripts which access MySQL databases. Firstly, you will, of course, need a webserver. We will, of course, be using he MVNU CS department web server, located at . Any web server software should work with PHP and MySQL but the typical to use is Apache, which is free. This is what we will use.

PHP also needs to be installed on the server. It is of course already installed on our CS server. You can also install it on your own personal computer (along with Apache and mySQL) to build yo u own web server! It can be downloaded from and is also free.

There is a simple test for both PHP and MySQL. Open a text editor and type in the following:
and save it as phpinfo.php

Now upload this to the CS server to a directory in your web space on the cs/ ( /var/www/classes/csc3031/username) and go to in in your browser: You will see a huge page with all the details of your PHP installation on it. Next, scroll down through all this information. You find a section about MySQL .

Although all the database administrative options can be done through PHP scripts, I most of the time such functions are done with PHPMyAdmin on the server. It is an excellent set of scripts that provides you with an administrative interface for your MySQL database(s). You can add, remove, edit, backup and view your databases using this and it is especially useful when troubleshooting your databases. We have used it in the past, and it can be found here:

Throughout this lab we will encounter some of the basics of using PHP and MySQL together. To do this we will be using a specific example all the way through. As you complete this lab, you will learn how to create a web based contact management program. It will allow you to store names with their addresses, e-mail and phone numbers. You will be able to update records and search the database. There will even be an option which allows you to send an e-mail out to all the people in the database (please note: this system should not be used for spam or unsolicited e-mail).

After creating this system you should have enough knowledge to go on and create nearly any type of database enabled site you want to.

In part 2 we will see how to set up your database in MySQL.

Part 2 >>

* Derived from

Topic revision: r2 - 2011-11-11 - JimSkon
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback