5.5. Adding new stock items

  1. Create an HTML form with appropriate fields for adding a stock item. Remember that the stock item's ID will be automatically filled in by the database, as it is an "auto increment" field. (A sample/answer form is available in your public_html directory as addstock.html)

  2. Write a script which uses CGI.pm to accept the form's parameters, then creates an SQL query to add a record to the database. Output a message to the user indicating the success (or failure) of the operation. A sample script to get you started is available in public_html/cgi-bin/addstock.cgi

5.5.1. Advanced exercises

  1. Check that the price is a number (use regular expressions for these checks)

  2. Check that it has two decimal places

  3. Check that the number of items in stock is a number

  4. Output meaningful error messages in each case (a sample validation script was given as an exercise in the CGI Programming in Perl training module, and a sample script provided as validate.cgi. If you attended that training module, you may like to use the sample script as an outline for this exercise)