Programming Assignment 4
A Message Board using PHP and MySQL

Due on Thursday March 19 before midnight


The goal of this project is to learn server-side web programming using PHP and a relational database system (MySQL). More specifically, you will create a message board where registered users can post messages.

This project must be done individually. No copying is permitted. Note: We will use a system for detecting software plagiarism, called Moss, which is an automatic system for determining the similarity of programs. That is, your program will be compared with the programs of the other students in class as well as with the programs submitted in previous years. This program will find similarities even if you rename variables, move code, change code structure, etc.

Note that, if you use a Search Engine to find similar programs on the web, we will find these programs too. So don't do it because you will get caught and you will get an F in the course (this is cheating). Don't look for code to use for your project on the web or from other students (current or past). Don't try to hire a freelancer to do the coding for you. Just do your project alone using the help given in this project description and from your instructor and GTA only.


As in the previous projects, you will develop this project on your PC/laptop using XAMPP and you will test it using using your Mozilla Firefox web browser. Download the project4 files: project4.tgz (for Linux and OS X) or (for Windows). Unarchive the files inside your web server document root directory. The project4 directory contains the file createDB.sql, which contains the SQL description of the tables: users and posts, that have the following schema:

users ( username, password, fullname, email )
posts ( id, postedby, follows, datetime, message )
Primary keys: users.username and
Foreign keys: posts.postedby->users.username and posts.follows->
To create the database, start the Apache Web Server and the MySQL Database on your PC using the XAMPP manager console. Run phpMyAdmin on your browser, create a new database with name board by clicking on New, select this database, go to the SQL tab and cut and paste the SQL code in createDB.sql and push Go. This will create your schema. You can test your setup on your web browser by using the URL address http://localhost/project4/board.php

The project4 directory also contains the file board.php, which needs to be changed as described in the description of the web application. The board.php file uses the PDO extension of PHP to insert a new user and to query the users table using MySQL.


Please read The PHP Data Objects (PDO) extension, especially the PDO class.

Project Requirements

Your script board.php must be able to produce 4 web pages (can be from the same script or you can split it into 4 different php scripts):

  1. Page1: a login form that has text windows for username and password, a "Login" button, and a "New users must register here" button.
  2. Page2: a "Logout" button, a "New Message" button, and the printout of all messages.
  3. Page3: a textarea with a "Post" button.
  4. Page4: a form to fill out user information along with a "Register" button
When board.php is executed for the first time, it displays Page1: From Page4, if the user pushes "Register" and the username doesn't already exist it goes to Page1; otherwise, it goes to Page4.
From Page2, if the user pushes "Logout", it should logout and go to Page1.
From Page3, if the user fills out the textarea and pushes the "Post" button, it will insert the new message in the database and will go to Page2.

For each posted message, you print:

To make the project easier, the messages must be printed ordered by date/time (oldest first) only. That is, you don't need to nest the replies.

Hints: Use md5 to encode passwords in PHP. Use uniqid to generate a unique id in PHP. Use the MySQL function now() to compute the current date and time.

What to Submit

Use the form below to submit your PHP file(s). We do not accept email or hardcopy submissions. You may submit your files as many times as you like, but only the most recently submitted files will be retained and evaluated (newly submitted files replace the old files under the same file name). After you submit the files, please double-check that your submitted files are correct by clicking on the Status link.

Submit Project #4:

Last modified: 03/04/15 by Leonidas Fegaras