(Assignment last updated: 5/27/2009 10:19:16 AM)  

Assignment 8 - Bookstore: Shopping Cart and Checkout

The checkout process is the most interactive part of the bookstore. In this assignment you will create the first steps of the checkout process: a) create a shopping cart, and b) obtain customer information. You will need to add an additional table to your database for storing customer information.  

Pages:

  1. shoppingCart.php -- The shopping cart uses a cookie to store the ISBNs of the books currently in the cart. Here is the code for a basic shopping cart (source). This code manages the information in the cookie but needs to be modified to list the names of the books in the cart and calculate costs.  Steps:
    1. Book titles need to be retrieved from the database. Dynamically build a SQL statement inside a foreach loop that includes the ISBN for each book in the cart. The syntax of the finished SQL statement will look something like this:
      SELECT isbn, title, price
      FROM bookdescriptions
      WHERE isbn='0596005431' OR isbn='0596006810' OR isbn='0596528124'
    2. To calculate shipping costs make up a simple pricing schedule something like: $5 for first item and $3 for each additional item. 
    3. Note on writing cookies: Some students may wish to write the total price, number of items, etc. to a cookie to display in a "shopping cart status box.." When writing a cookie after a significant about text has been output you may receive the error ""Cannot modify header information - headers already sent." This problem is easily solved by turning on the output buffer (see ob_start).
         
  2. checkout01.php -- This page requests the customer's email address. It also displays the number of items in the cart.
     
  3. checkout02.php -- This page queries the database for the email address entered in checkout01.php. If the email is found it displays the customer's information in textboxes. If not found it populates only email textbox. Steps:
      1. Create a new table in the database to store customer information. Name it bookCustomers and create the following fields for the customer information:
        Field Type Null Extra
        custID int(11) No auto_increment, primary key
        fname varchar(20) No  
        lname varchar(20) No  
        email varchar(50) No  
        street varchar(25) No  
        city varchar(30) No  
        state varchar(2) No  
        zip varchar(5) No  
      2. You will need some sample customer data for testing your php code. Use phpMyAdmin to add one or two customer records.
         
      3. The customer greeting changes depending upon whether their email is found in the database. After querying the database the code to check if the user is found looks something like this:
        1. if (mysql_num_rows($result) == 0 ) {
          echo "New Customer - Please provide your shipping address.";
          }
          else {
          echo "Returning Customer - Please confirm your mailing and e-mail addresses.";
          $row = mysql_fetch_array($result);
          }

      4. Use the same HTML form to collect user information for both new and returning customers. To populate the textboxes with database data use the syntax:
        value="<? echo $row['fname'];?>"

        This will display the value from the database if a customer was found and display a blank text field if not found. The email address entered by the user in checkout01 is always displayed.
         

  4. When you submit the assignment for grading include an email address that is in the database. This will allow the grader to see if the form preloads the customer information from the database. The data will be written to the database in checkout03.php (assignment 9).


Check your URLs to make sure they are correct before you submit them for grading.  The subject line of your email should read "MIS314 Ax YourName" where x is the assignment number. Send an email with the appropriate URLs to: 

  1. Professor Sandvig at (note: this address is for homework assignments only. Please send other email to )
  2. The class teaching assistant, Emma James, at
  3. cc a copy to yourself (as a time-stamped receipt of your submission) 

When pages are connected via navigation it is only necessary to submit the URL to the first page.