CGI and Perl

Guest Book

One of the most common CGI applications out on the Web today is the guest book. Everyone wants to build up a customer contact list, and what better way to do it than on the Web? The paradigm of direct-mail is slowly being replaced by the guest book application on the World Wide Web. One of the best ways to find sales leads is to monitor the people who visit your Web site. This example shows how to implement this application easily with Perl5 and the WWW libraries.

Determining Fields of Information

Before you actually start writing code, it would be a good idea to figure out what information fields you want to store about the visitors. The obvious information comes to mind first: name, title, company, address, phone number(s), fax number, e-mail address. There may be others that are specific to your business. Let's also include these for this example: How did you hear about us? What products are you interested in? Comments/feedback.

Determining Fields of Information

Before you actually start writing code, it would be a good idea to figure out what information fields you want to store about the visitors. The obvious information comes to mind first: name, title, company, address, phone number(s), fax number, e-mail address. There may be others that are specific to your business. Let's also include these for this example: How did you hear about us? What products are you interested in? Comments/feedback.

Setting Up the Database

A very important piece of work in the initial design is deciding on how you will store the data. For simplicity's sake this example stores the information in a plain text file, with fields separated by a delimiting set of characters. There's no reason why you couldn't store the information into a relational or object database. There are several modules available that address the need of connecting Perl to relational databases. If you are interested in this capability, search the CPAN for ODBC modules.

In this example, you define one row in a file to be a single visitor. Our delimiting characters will be <*>. Therefore, the database would be structured like the following:

Name<*>Title<*>Company<*>Address<*>City<*>State<*>Zip<*>Phone<*>Fax<*>
 Âe-mail<*> How<*>What<*>Comments

You'll define a distinct set of values for How and What. For example, How might include Friend, Magazine, Salesperson, Newspaper, and Television. You would define What as an array of products that are in our product line.

by BrainBellupdated
Advertisement: