Web Teacher Software
web database
Javacript 
Tutorial
CGI tutorial
web 
database consulting
web database training
contact us about web 
database software
press
Hosted Database Solutions
webteacher home
Web Teacher Consulting
CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl


Writing to Files


For the next section we will create a page which allows the visitor to enter information into a guestbook.  Guestbook programs are often preferable to e-mail because the information is stored in a database, which means it can be sorted, filtered, manipulated, and exported.

<SHAMELESS PLUG>
If you do not want to write all the code for adding, deleting, and modifying data, I have created a database program which you can use instead. Check out Webteacher's Webdata - the EASIEST database for the web.
</SHAMELESS PLUG>

In order to create this guestbook, we are going to create 3 files in the perltour folder.

  1. guestbook.htm  - the form which the user will fill out on his/her browser
  2. guestbook.cgi   -  the program to get the values from the web page and process them

  3. If you use a cgi-bin, the guestbook.cgi program will eventually go there.
  4. guestbook.log  - a delimeted text file to hold all of the stored data.

The process is simple. guestbook.cgi is a program which will get the name, address, city, state, zip, phone number, and comments from the web page, and append them as a new line in the guestbook.log file.

To begin with, let's create the HTML page for your visitors to sign in.  This form contains 10 elements, plus a submit button.
Copy this page to your word processor, and name it guestbook.htm

Remember, if your server uses a cgi-bin, you need to add /cgi-bin/ before guestbook.cgi in the <FORM> tag.

 

When you have created the file, upload it to the perltour folder.



<HTML><HEAD>
<TITLE> My Guestbook Page </TITLE>
</HEAD><BODY bgColor="beige">

<H1 ALIGN='CENTER'> Please sign our guestbook </H1>
<TABLE BORDER=0 width=100%>
<FORM ACTION="guestbook.cgi" METHOD="post">

<TR><TD> First Name  <TD> <INPUT TYPE=TEXT NAME="first" SIZE=25>
<TR><TD> Last Name  <TD> <INPUT TYPE=TEXT NAME="last" SIZE=25>
<TR><TD> Address  <TD> <INPUT TYPE=TEXT NAME="address" SIZE=40>
<TR><TD> City <TD><INPUT TYPE=TEXT NAME="city" SIZE=25>
<TR><TD>State <TD><INPUT TYPE=TEXT NAME="state" SIZE=2>
<TR><TD>Postal Code <TD><INPUT TYPE=TEXT NAME="postal" SIZE=9>
<TR><TD> Telephone  <TD> <INPUT TYPE=TEXT NAME="phone" SIZE=25>
<TR><TD> e-mail  <TD> <INPUT TYPE=TEXT NAME="email" SIZE=25>
<TR><TD> Add me to<BR>your mailing list <TD><INPUT NAME="maillist" TYPE=CHECKBOX CHECKED>
<TR><TD> Comments  <TD>
<TR><TD COLSPAN=2><TEXTAREA NAME="comments" ROWS=6 COLS=80></TEXTAREA>
<TR><TD><TD> <INPUT TYPE="SUBMIT" VALUE="Send my comments">
</FORM>
</TABLE>

</BODY></HTML> 

BACKOn to the Log file.


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