Fall Semester 2002


Lab Notes Eight: A PHP Shopping Cart

The plan for this lab is this:

What follows, then, is your

A348/A548 LAB ASSIGNMENT EIGHT

Start by preparing your database by creating three tables, and populating them with data.

burrowww.cs.indiana.edu% mysql -ua348 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3402 to server version: 3.23.27-beta

Type 'help;' or '\h' for help. Type '\c' to clear the buffer

mysql> use a348
Database changed
mysql> show tables like "dgerman_php%";
+-------------------------------+
| Tables_in_a348 (dgerman_php%) |
+-------------------------------+
| dgerman_php_books             |
| dgerman_php_catboo            |
| dgerman_php_categories        |
+-------------------------------+
3 rows in set (0.01 sec)

mysql> describe dgerman_php_categories;
+---------+------------------+------+-----+---------+-------+---------------------------------+
| Field   | Type             | Null | Key | Default | Extra | Privileges                      |
+---------+------------------+------+-----+---------+-------+---------------------------------+
| catid   | int(10) unsigned |      | PRI | 0       |       | select,insert,update,references |
| catname | char(40)         |      |     |         |       | select,insert,update,references |
+---------+------------------+------+-----+---------+-------+---------------------------------+
2 rows in set (0.00 sec)

mysql> select * from dgerman_php_categories;
+-------+-----------------------------+
| catid | catname                     |
+-------+-----------------------------+
|     1 | Mechanics                   |
|     2 | Typesetting                 |
|     3 | Computers                   |
|     4 | Mathematics                 |
|     5 | Scheme                      |
|     6 | Programming                 |
|     7 | Interpreters                |
|     8 | Compilers                   |
|     9 | Games                       |
|    10 | Number Theory               |
|    11 | Perl                        |
|    12 | Object-oriented programming |
|    13 | Semantics                   |
|    14 | Logic                       |
|    15 | Physics                     |
|    16 | Quantum Physics             |
|    17 | General Physics             |
|    18 | Graduate Math               |
|    19 | Cryptography                |
|    20 | Topology                    |
+-------+-----------------------------+
20 rows in set (0.00 sec)

mysql> describe dgerman_php_books;
+-------------+-------------+------+-----+---------+-------+---------------------------------+
| Field       | Type        | Null | Key | Default | Extra | Privileges                      |
+-------------+-------------+------+-----+---------+-------+---------------------------------+
| isbn        | varchar(6)  |      | PRI |         |       | select,insert,update,references |
| author      | varchar(60) | YES  |     | NULL    |       | select,insert,update,references |
| title       | varchar(90) | YES  |     | NULL    |       | select,insert,update,references |
| price       | float(4,2)  |      |     | 0.00    |       | select,insert,update,references |
| description | text        | YES  |     | NULL    |       | select,insert,update,references |
+-------------+-------------+------+-----+---------+-------+---------------------------------+
5 rows in set (0.00 sec)

mysql> select * from dgerman_php_books;
+--------+----------------------------------------------------+-----------------------------------------------------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| isbn   | author                                             | title                                               | price | description                                                                                                                                                                                                                                                                                                          |
+--------+----------------------------------------------------+-----------------------------------------------------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| pes001 | Michael E. Peskin, Daniel V. Schroeder             | An Introduction to Quantum Field Theory             | 65.00 | This book is a clear and comprehensive introduction to quantum field theory, one that develops the subject systematically from its beginnings. The book builds on calculation techniques toward an explanation of the physics of renormalization.                                                                    |
| sus001 | Gerald Jay Sussman, Jack Wisdom, Meinhard E. Mayer | Structure and Interpretation of Classical Mechanics | 60.00 | This textbook takes an innovative approach to the teaching of classical mechanics, emphasizing the development of general but practical intellectual tools to support the analysis of nonlinear Hamiltonian systems. The student actively explores the motion of systems through computer simulation and experiment. |
+--------+----------------------------------------------------+-----------------------------------------------------+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.01 sec)

mysql> describe dgerman_php_catboo;
+-------+------------------+------+-----+---------+-------+---------------------------------+
| Field | Type             | Null | Key | Default | Extra | Privileges                      |
+-------+------------------+------+-----+---------+-------+---------------------------------+
| isbn  | char(6)          |      | PRI |         |       | select,insert,update,references |
| catid | int(10) unsigned |      | PRI | 0       |       | select,insert,update,references |
+-------+------------------+------+-----+---------+-------+---------------------------------+
2 rows in set (0.00 sec)

mysql> select * from dgerman_php_catboo;
+--------+-------+
| isbn   | catid |
+--------+-------+
| fey001 |     1 |
| sus001 |     1 |
| dek003 |     2 |
| dek003 |     3 |
| gkp001 |     3 |
| hpb001 |     3 |
| con002 |     4 |
| dek003 |     4 |
| gkp001 |     4 |
| hpb001 |     4 |
| kob001 |     4 |
| mun001 |     4 |
| fri001 |     5 |
| fri002 |     5 |
| con001 |     6 |
| fri001 |     6 |
| fri002 |     6 |
| hpb001 |     6 |
| fri001 |     7 |
| fri002 |     7 |
| fri001 |     8 |
| con002 |     9 |
| fri002 |     9 |
| con002 |    10 |
| kob001 |    10 |
| con001 |    11 |
| con001 |    12 |
| fri001 |    12 |
| hpb001 |    13 |
| hpb001 |    14 |
| fey001 |    15 |
| pes001 |    15 |
| sus001 |    15 |
| fey001 |    16 |
| pes001 |    16 |
| fey001 |    17 |
| kob001 |    18 |
| mun001 |    18 |
| kob001 |    19 |
| mun001 |    20 |
+--------+-------+
40 rows in set (0.01 sec)

mysql> exit
Bye
burrowww.cs.indiana.edu% exit
burrowww.cs.indiana.edu% 
You got to this point, that's just great.

Here's a tidbit we always forget to mention:

Creating a table that has a combination of columns as the primary key:

create table catboo (
  isbn char(6), 
  catid int unsigned, 
  primary key (isbn, catid)
) 
Not now, though.

Now that you have these let's think for a moment what you will be doing with them.

You will be using SQL to retrieve information from these tables.

Perhaps just remembering that there is a comprehensive SQL review available (that was posted as Lecture Notes Ten, a few semesters ago) would be reassuring enough. Alternatively you might need some help in the lab with the database.

So let's put together the program.

Or, at least, let's get started.

Dedicate a place to the scripts for this lab.

I suppose ~/apache/apache_1.3.22/htdocs/lab8 is good enough.

Then create this file in it.

Then add whatever the document above takes you to (through its links).

(All the files, as indicated below).

The link above completely documents the first aspect of the program.

So it basically offers the following structure:

Every arrow means "invokes," or "calls".

Backwars, obviously, it means "is called by".

Notice there's only one file, but 8 (eight, not nine) functions.

Your task is: to get this done.

Here's my version of it. (Please shop Physics)

Notice that two things are not explained here yet but work in the demo:

But all categories are retrieved from the right table.

The missing part will be posted next week, in the same format as today's.

(Or, see below. You never know what may be posted already).

So this is your

A348/A548 LAB ASSIGNMENT EIGHT

As an UNDERGRADUATE

1. Implement all of the above.

2. Finish get_book_cats() from the lecture.

As a GRADUATE do this in addition to all of the above:

Think on what it takes for the the full demo presented to be implemented.

Here's all of the source code for you to review:

  1. One.php
  2. checkout.php
  3. index.php
  4. show_book.php
  5. show_cart.php
  6. show_cat.php

The CREATIVITY option

Create your own tables, entries, pictures, categories, etc.

Good luck and let us know if we can help.


Last updated: Oct 18, 2002 by Adrian German for A348/A548