July 2000
Intermediate to advanced
492 pages
14h 53m
English
Our first CGI script, which is shown in Example 2.2, is written in Perl. I used ActivePerl (from
http://www.ActiveState.com) on a
Windows 2000 Workstation machine. The Perl 5 CGI script is very
straightforward. Read the comments (those lines starting with a
# character) to understand the code line by line.
Example B.2. The Perl Version of the CGI Script
# Use the CGI and OLE perl modules.
use CGI qw(:standard);
use OLE;
# Instantiate an ADO Connection object and open the database.
$conn = CreateObject OLE "ADODB.Connection" || die "CreateObject: $!";
$conn->Open('LangPref');
# Retrieve the Name and Language Preference of the user.
$Name = param("UsrName");
$LangPref = param("ProgLang");
# Construct the SQL INSERT statement.
$sql = "INSERT INTO LangPrefStorage (Name, LangPref) VALUES (\'$Name\', \'$LangPref\')";
# Execute the SQL INSERT statement and close the ADO connection.
$conn->Execute($sql);
$conn->Close( );
# Print out the "Thank You" message in an HTML
# form to the user.
print header,start_html("Language Preference Storage"),h1("Thank you, $Name.");
print p("Click <A HREF = '/~wsdocs/langform/formsample.htm'>here</a> to reset the form.<BR>");
print end_html;Once the user has entered her name and programming language preference and clicked on the Submit button, this script will save the information to the database and send the response shown in Figure 2.2 back to the user.
Figure B.2. The CGI reply
The Perl code is straightforward. First the script imports ...
Read now
Unlock full access