ASP Advanced Tutorial Ⅱ: A simple guest book

Source: Internet
Author: User


Starting from this chapter we will enter our tutorials by a simple, guest book program that uses file storage to access the message. To write such a guest book, we can roughly take the following three steps to complete.
Step one: First design a message form page (such as: guestbook1.asp, this does not need me to preach here? )。 See figure below:
Step two: After the design of the message form, we began to write processing the message of the ASP program.
We want to write the processing of the ASP program message, the most important question is how to implement access to the message. In the ASP program, to access the file, we must establish the FileSystemObject object (which is used primarily for reading Unicode or ASCII files). To create a FileSystemObject object, we can use the following statement:
SET Object instance = CreateObject ("Scripting. FileSystemObject ")
Methods for FileSystemObject objects include: CreateTextFile and OpenTextFile:
CreateTextFile: Create a file name and return a TextStream object to provide you with read and write files
OpenTextFile: Open an existing file and create a TextStream object for you to read and write files after you create and open an editable file, we can finally invoke the method WriteLine under the TextStream object ( Writes information to an open file and wraps it, and method ReadLine (reads one line of information for an open file) to access the file.
Therefore, to achieve access to the message of the ASP program, we can be roughly conceived as follows:
Create a FileSystemObject object first, and then invoke OpenTextFile to open the file or call CreateTextFile to make a new file, and to establish a TextStream object Finally, we make a call to the TextStream object's WriteLine and ReadLine to access the file. After solving this problem, we can write the ASP program that handles the message as follows:
<%
Name = Request ("Name")
email = Request ("email")
Subject = Request ("Subject")
Memo = Request ("Memo")
Get data from a message form
If Name = "" or Email = "" or Subject = "" or Memo = "" Then
Response.Write "Input box cannot be blank!"
Response.End
End If
Check the form's input boxes for information input, if left blank input box does not fill out the display information: "The input box can not be blank!" and stop executing the following program.
Line1 = "Message person:" & Name
Line1 = Line1 & String (5, "")
email = "< A href=mailto:" & email & ">" & Email & "</a>"
Line1 = Line1 & "Email? "& Email & < Br>"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.