Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1





After you receive this page, the first thing to notice is the names of the <input> fields. These are the
names you will need to access the values that are passed from this page to your CGI script and then
added to the database. Another thing to look at is the <form> tag. Make sure that it is pointing to the
right script and that the method property is set to POST.

Creating the Script


Now it is time to create the Perl Script. Because this is a production application, you want to make sure that
the data you are putting into your database is correct. Therefore, you will validate the data in your script. This
could also be accomplished on the client side with JavaScript but, because you are doing a script, you'll see
how you can check your data there.
Listing 21.2 shows the AddCustomer.pl script.
Listing 21.2 Script for Adding Customers


#!/usr/local/bin/perl


use DBI;


&GetFormInput;


The intermediate variables below make your


#script more readable


#but somewhat less efficient


#since they are not really necessary.


$FirstName = $field{'FirstName'} ;


$LastName = $field{'LastName'} ;


$Middle = $field{'Middle'} ;

Free download pdf