[an error occurred while processing this directive] CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl

The Guestbook CGI code


#********* BEGIN BODY********************

open (LOGFILE, ">>guestbook.log");

$newline=join('::',@value);

print LOGFILE ("$newline\n");

close LOGFILE;

print "<BODY BGCOLOR='BEIGE'><H1>Thank you. ";
print "Your comments have been added</H1>";

#******** END BODY************************


The first line of the code is this:
open (LOGFILE, ">>guestbook.log");

The next line is the join statement.  This is an extremely useful tool for adding data to delimited text files.  The statement
$newline=join('::',@value);
means take each value in the @value array (each entry box on the HTML form), and join them with double colons.

$newline could now contain this:
Robert::Young::5 Main St.::Anytown::MA::02177::(617) 555-1212::robyoung@mediaone.net::on::This is Great

Now that $newline is complete, I am ready to add it to the end of guestbook.log.  Since I already have a file handle for the log file, appending to it is as easy as this:
print LOGFILE ("$newline\n");
It will add the entire contents of $newline to the end of guestbook.log.  I also asked it to add a \n (carriage return) to the end of $newline, so that the next time I append something, it will start at the beginning of a new line.

close LOGFILE;
It stands to reason that if I have to open a connection to the file when I begin my program, I should close that connection when I am through.

Lastly, I printed something to the screen.  This is more than just a courtesy.  You have to write something or else you get a 'document contains no data' error.  So we wrote this:

print "<BODY BGCOLOR=\'BEIGE\'><H1>Thank you.  Your comments have been added</H1>";
 
 
 
BACKHow do I get the data?


Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room