Programming Assignment 2
PHP Scripting

Due on Thursday February 19 before midnight


Description

This project must be done individually. No copying is permitted. The goal of this project is to learn server-side web programming with database connectivity using PHP. More specifically, you will develop a bookstore web application where customers can buy books listed in a database.

Platform

For this project, you will use the Omega web server. Login to omega.uta.edu. Please call UTA OIT if you have problems with your omega account. Look at your path using the command pwd. For example, if your username is smith, you will see:

/home/s/sm/smith
In the following, change the path /home/s/sm/smith to your own path. Create the directory public_html if doesn't exist. Then do:
cd public_html
mkdir project2
chmod 711 project2
cd project2
Then create a file .htaccess (note: it starts with a dot) inside the project2 directory with the following content:
AuthType Basic
AuthName "Running Project2"
AuthUserFile /home/s/sm/smith/public_html/project2/.htpasswd
<Limit READ GET POST>
require valid-user
</Limit>
(of course, change /home/s/sm/smith to your own path). Then create the password file using:
htpasswd -c .htpasswd smith
(use your username instead of smith). It will ask you for a password twice. This is the password you use when you run your PHP scripts on a browser. For this project, you should put all your PHP and HTML files in the project2 directory. Don't put PHP scripts in a cgi-bin directory. You can test your setup by using the following PHP file test.php inside your project2 directory.
<?php print "Hello!"; ?>
For user smith, you can run it using:
http://omega.uta.edu/~smith/project2/test.php
Note that if a script doesn't require GET/POST parameters, then you can test it by running it on omega using php. For example, php test.php

You can work on mySQL on Omega using the web site http://omega.uta.edu/myadmin/. You must login using your omega username and your default password (the one that you use when you reset your password). Please call OIT if you have forgotten your default password. Then you click on the database that has the same name as your username and create your tables. There is online documentation on this web page, but basically the GUI is easy to use without reading any manual. This web site allows you to create and populate tables, and query, insert, delete, and update data.

Documentation

The following are tutorials on PHP. Use them as a reference only.

Here is an example of a PHP script on omega that uses mysql (replace smith with your username and xxxxxx with your password):
<?php
if (!$dbh = mysql_connect("localhost","smith","xxxxxx")) {
   die("Error ". mysql_error());
}
mysql_select_db("smith");
if (! $sth = mysql_query("select * from employee")) {
   die("Error query ". mysql_error());
}
while ($ar = mysql_fetch_row($sth)) {
  foreach ($ar as $col)
    print "$col";
  print "<br/>\n";
 }
?>
Here is a script that uses sessions:
<?php
session_start();
if (!isset($_SESSION['count']))
    $_SESSION['count'] = 0;
$_SESSION['count']++;
print 'you have visited ' . $_SESSION['count'] . ' times';
?>

Project Requirements

You will develop a trivial web application that allows customers to buy books. For this project, assume that each book has only one author. You need to store the books in your mySQL database. You should insert at least 20 books. You should create two PHP scripts: buy.php (the startup script) and checkout.php. The communication between these two scripts should be done with session data and get/post parameters. The web page generated by buy.php should have the following components:

The checkout.php script gets the selected books (from the get/post parameters and the $_SESSION), prints them, and prints the total amount due (the sum of the prices of all selected books).

Note: Like in the first project, you should not use any tool that generates code. You only allowed to use a text editor to write your scripts.

What to Submit

Create a Readme.txt file that contains the following information:

URL on Omega:
htaccess username:
htaccess password:
where URL on Omega is the URL the GTA should use to run your program (eg. http://omega.uta.edu/~smith/project2/buy.php), and htaccess username and password are those needed for the GTA to login to your application.

On the omega mySQL web page, select Export, then select SQL (the default) and "Save as file", and push Go to create a .sql file with your schema and data. Use the form below to submit your Readme.txt, PHP and .sql files. You may submit each file as many times as you like, but only the most recently submitted file will be retained and evaluated.


Submit this file:


Last modified: 02/15/09 by Leonidas Fegaras