Design now talk about book.htm, let everyone know the role of the input form, its action object is itself, book.asp (wait for a while to rename book.htm to book.asp) This file, that is. After the form is submitted, it is handled by itself. In this form, there are several text input boxes, which are name,sex,from,url,email, and multiple lines of text input boxes comments.
Now rename book.htm to book.asp and add ASP code to the file. as follows: (single quotation marks represent an ASP's analysis, the compiler is not processed.)
*book.asp
<% @language = "VBScript"%>
<%
"To determine the request, when the client requests the file, such as direct input URL: http://active.silversand.net/index.htm This way, you will produce a GET request information. When the form is submitted (the form is set to post), it will produce a POST request, and now judge whether the book.asp file is the user to open the page in the browser, or the user submits the data this action, in order to process.
If Request.ServerVariables ("request_method") = "POST" Then
' Here the page is judged by the user submitting the form, so the registration message is processed.
' Create a server instance of a file component
Set Fsfilesys=createobject ("Scripting.FileSystemObject")
' Open Text file Server.MapPath ('/') is the true path to return to the server's release directory, i.e., c:\Inetpub\wwwroot this path and then "/realchat/book/book.txt" Is the path that is based on this path.
Set Mytext=fsfilesys.opentextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
' Read all the contents of the text file and save it in the TEMP variable.
Temp=mytext.readall
Mytext.close
' Whether you need to add content
If Request ("task") = "Insert" Then
' Get the values of the items in the form
Tname=request.form ("name")
Tsex=request.form ("Sex")
Temail=request.form ("email")
Turl=request.form ("url")
Tfrom=request.form ("from")
Tcomments=request.form ("comments")
Ttime= "#&@" &time
If Len (tcomments) <2 Then
%>
<font size= "4" color= "Red"
<p align= "Center" > I'm sorry! You haven't left a message yet. <a Href= "Book.asp" to return to </a> </font> <%
Else
If Lcase (left (turl,7)) <> http://Then
Turl= "http://" &turl
End If
Turl=lcase (Turl)
' Recreate the data file and overwrite the original.
Set Mytext=fsfilesys.createtextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
Mytext.writeline (Tname)
Mytext.writeline (Tsex)
Mytext.writeline (Temail)
Mytext.writeline (Turl)
Mytext.writeline (Tfrom)
Mytext.writeline (tcomments)
Mytext.writeline (Ttime)
Mytext.writeline (date)
Mytext.writeline (Temp)
Mytext.close
%>
<script language= "JavaScript" >
document.write ("</script>
<%
End If
' At this point, the message has been saved in the file Book.txt
End If
Else
' The first time you enter the input screen, so the contents of the HTML file are displayed.
%>
<title> Message Book </title>
<% colorbg= "#BED9FC"%>
<body bgcolor= "<% =colorbg%>" background= "Images/bg.gif"
<p align= "center" >Height= "" "> </p>
<p align= "center" >[<a href= "disp.asp" I want to see the message board </a>] [<a Href=]. /index.asp "> back home </a>] </p>
<form method= "POST" action= "book.asp"
<input type= "hidden" name= "task" value= "Insert" ><div "left" <table>
<tr>
<TD align= "right" > name </td>
The <td> </td>
<td> <input name= "name" size= "+" </td>
</tr>
<tr>
<TD align= "right" sex </td>
The <td> </td>
<td> <input name= "Sex" size= "+" </td>
</tr>
<tr>
<TD align= "Right" from the </td>
The <td> </td>
<td> <input name= "from" size= "+" </td>
</tr>
<tr>
<TD align= "right" homepage URL </td>
<td> </td>
<td> <input name= "url" size= "+" </td>
</tr>
<tr>
<TD align= "Right"
E-Mail </td>
<td> </ td>
<td> <input name= "Email" size= "+" </td>
</tr>
<tr>
<TD align= "right" > message </td>
<TD colspan= "2" ><textarea wrap= "Off" name= "comments" cols= "$" rows= "9" > </textarea> </td>
</tr>
<tr>
<td> </td>
<TD colspan= "2" > <dl>
<DD align= "center" > <input type= "Submit" value= "I have written"
<input type= "reset" value= "re-write" > </dd>
</dl>
</td>
</tr>
</table>
</div>
</form>
<p align= "center" > </p>
</body>
<%
End If
%>
Now to disp.asp this file, this file mainly completes extracts the file content from the Book.txt, then rebuilds the HTML code to display the message content.
The code is as follows:
<% @language = "VBScript"%>
<title> Message Book </title>
<body background= "Images/back.gif"
<p align= "center" ><%
' Open Data file
Set Fsfilesys=createobject ("Scripting.FileSystemObject")
Set Mytext=fsfilesys.opentextfile (Server.MapPath ("/") & "/realchat/book/book.txt")
Tname=mytext.readline
%> </p>
<p align= "center" >[<font color= "#00FFFF" size= "4" ><a href= "book.asp" > > I want to write a message </a> </font>][<font color= "#00FFFF"