A7: Collecting User Input

On This Page


Overview

During this assignment, you will:

  • Collect data using an HTML form
  • Send the form data to a PHP script
  • Save the data in your project database
  • Document your PHP code

Specifications

This assignment has several parts:

  1. Create an HTML form for your project, named dbform.php, that collects information from users. The page must include (or require) both a header.php and a footer.php file.
  2. Using the specified file name makes grading easier. After you turn in the assignment, you can change the name of the page for your final project if you want.

  3. Create a PHP script, named dbinsert.php, that collects the form data and performs the following:
    1. Displays the data entered
    2. Displays all SQL statements used to save data in your database
    3. Inserts the data in your database (using an INSERT statement)
    4. Reports the number of rows affected

    You must store the data from the form in at least two "joined" tables of your database. This is so you understand how to store data in two different tables that can be retieved using a SQL join.

  4. Place your code for the start of a page into a file named header.php. This file must include the following HTML tags:
    1. Opening HTML tag
    2. Opening and closing header tags
    3. Opening and closing title tags with your project's name enclosed
    4. Opening body tag
  5. Place your code for the end of a page into a file named footer.php. This file must include the following HTML tags:
    1. Closing body tag
    2. Closing HTML tag
  6. Export your database design as SQL statements to a dbname.sql file.
  7. Name the file after your database and add the extension .sql to the name. Make sure your tables are in a loadable order. If you use InnoDB tables, you may need to arrange your table order manually. Thus, make sure you test your dbname.sql file before submitting it.

    Make sure of the following about your dbname.sql file:

    • Does not contain a SQL 'USE' or 'CREATE DATABASE' statement
    • Includes DROP TABLE IF EXISTS statements for all tables
    • Is compatiable with MySQL version 4.0.X

    Note that phpMyAdmin supports all these behaviors if you check the correct checkboxes.

  8. Create a PHP comment at the top of all your PHP pages formatted like the following:
  9. /**
    * CIS-165PH  Asn 7
    * dbentry.php
    * Purpose: Processes form data and saves it in
    * my project database.
    *
    * @author Ed Parrish
    * @version 1.0 10/23/05
    */
    

    For more information on documenting PHP code, see: How To Document PHP Code.

  10. In your README.txt file provide instructions on using this assignment. For example, if a password is required, please include a password. If any values are required for a form, please provide the values.
  11. Place the following files in the web-application root directory
    1. README.txt file
    2. dbform.php file
    3. dbentry.php file
    4. dbname.sql file
  12. Place the following files in a subdirectory named includes
    1. header.php
    2. footer.php
  13. Your PHP code must use the included file includes/dbconvars.php for all database connection arguments.
  14. Even though you do not need to submit your dbconvars.php file, the instructor will use one to test your work. Failure to use a dbconvars.php file will result in a poor grade.

  15. Zip your project and all files and subdirectories you plan to submit using a zip utility such as WinZip or gzip.
  16. Zip from the project directory and NOT from the parent directory of the project. For full credit, you need to make sure your files do not unzip into a single directory.

Application Structure

    README.txt
    dbform.php
    dbentry.php
    dbname.sql
    includes/
             dbconvars.php
             header.php
             footer.php
    

    Note that the above shows the required files and subdirectories. You may add more files and subdirectories as needed by your project..

Sample Input Form

First Name: 
Last Name: 
Address: 
City/Township: 
State/Province: 
Zip/Postal Code: 
Country: 
Phone: 
 

Sample Output

Data Entered:

First name: Fred
Last name: Flintrock
Address: 123 Rocky Road
City/Township: Bedrock
State/Province: CA
Zip/Postal Code: 12345
Country: USA
Phone: 555-1234

SQL: INSERT INTO addresses(Address, City, State, Zip, Country ) VALUES ('123 Rocky Road', 'Bedrock', 'CA', '12345', '555-1234')

Rows affected: 1

SQL: INSERT INTO customers(LName, FName, AddressID, Phone) VALUES ('Flintrock', 'Fred', 5, '555-1234')

Rows affected: 1

Extra Credit

The following are worth extra credit points:

  1. Read ahead in the textbook and use conditional statements to validate the user input. For instance, display an error message if the user leaves a field blank and let the user re-enter their data. (1-2 points depending on difficulty)
  2. In addition to the above, perform a query on your database to prevent users from re-entering an already existing row of data. (2 points)

Make certain that your README.txt file lists any extra credit attempted.

Grading Criteria

The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.

Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.

For information on grading policies, including interpretation of scores, see the course Syllabus.

Database Export

  • 2: Database loads from dbname.sql file with no errors or warnings
  • 1: Database loads from dbname.sql file but has errors, warnings or missing data
  • 0: Does not load or dbname.sql file not submitted

PHP Functionality

  • 10: Demonstrates mastery of the assignment
    • Has extra features or demonstrates techniques beyond the assignment
    • Applies concepts from the lesson(s) appropriately
    • Meets all specifications (see above) with particularly elegant solutions
    • No errors encountered during operation
  • 8: Has all the functionality expected of the assignment
    • Demonstrates many techniques from the lesson
    • Meets all specifications (see above)
    • Implementation seems more complicated than necessary.
    • May have one minor error
  • 6: Has most of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets all but one of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have 2-3 minor errors
  • 4: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets at least 1/2 of the specifications (see above)
    • Implementation seems excessively complicated.
    • May have more than 3 minor errors
  • 2: Serious functional problems but shows some effort and understanding
    • Meets less than 1/2 of the of the specifications (see above)
    • Has a major error or many minor errors
    • Implementation seems very convoluted
    • Demonstrates few techniques from the lesson
  • 0: Does not execute

HTML Code

  • 4: Demonstrates mastery of HTML
    • Has extra features or demonstrates techniques beyond the assignment
    • Meets all specifications (see above) with particularly elegant solutions
    • No errors in the HTML code (both opening and closing tags used)
  • 3: Has mostly correct HTML code
    • Demonstrates many techniques from the lesson
    • Meets all specifications (see above)
    • May have 1-2 minor HTML errors.
  • 2: Has some of the functionality expected of the assignment
    • Demonstrates some techniques from the lesson
    • Meets some of the specifications (see above)
    • May have 4-5 minor errors
  • 1: Serious problems but shows some effort and understanding
    • Demonstrates few techniques from the lesson
    • Meets few of the of the specifications (see above)
    • Has many errors
  • 0: No HTML file submitted or page does not display anything

Documentation

  • 2: Code is well-documented
    • Name, date, and page description in page comment block
    • Follows format for page comment block
    • Proper use of whitespace and indenting
    • Files are correctly zipped
  • 1: Code has minor documentation errors
    • Has documentation errors
  • 0: No apparent attempt at documentation

README.txt File

  • 2: README.txt file submitted with specified information included
  • 1: README.txt submitted but some information was not included
  • 0: No README.txt submitted

Maximum Score: 20, plus extra credit

What to Turn In

Submit a zipped file with all required files in the specified directories following the instructions for homework. Your .zip file must include all the files and subdirectories needed to make your assignment function properly. Do not assume that the instructors has any files except dbconvars.php. Your assignment must work as submitted.

Home | WebCT | Announcements | Course info | Expectations | Schedule
Project | Help | FAQ's | HowTo's | Links

Last Updated: March 29 2006 @17:20:46