Example analysis: Using ASP to build a small web BBS system

Source: Internet
Author: User
Tags date insert reset
Web pages of traditional Web BBS is mostly implemented by CGI, its implementation requires programmers to master programming languages such as Perl or C, but also to understand the CGI model of the various technical content, so to make their own web BBs really difficult. ASP (Active Server Pages Dynamic Server home page), so that we see a bright, can use ASP to achieve Web BBS it? Of course the answer is yes. The allure of ASP is that it provides a simple and easy to learn script, with many built-in objects, thus providing a simple way of programming.

The BBS mainly by the user registration (browser-side), user registration (server-side), plus posts (browser-side), add posts (server side), post specific content of the display and reply, as well as the display of all posts six components, The user information is stored in the database Author.mdb, the post is stored in the database Bbs.mdb. They are all Access databases, which are shown in tables 1, 2, respectively.

Table 1 Author.mdb


Field name data type length description
AuthName Text 24 User name
Password Text 10 password


Table 2 Bbs.mdb


Field name data type length description
ID Text 4 Number of posts
AuthName Text 24 User name
Subject Text 80 Themes
Content Comment Contents
Adddate Date/Time Posted date
Visitnum Digital long-integer visitors
Number of Answernum text 4 reply post
(Default is the number of itself)
Addtime Date/Time Add paste time
Topnum Text 4 Number of the first level reply post


The implementation method is as follows, where ASP files and databases are stored in "/hosp/asp", other HTM
Files are stored in "/hosp" Files, and img files are stored in "/hosp/images".

1, user registration (browser-side) login.htm: the user input relevant information, through the form sent to the service
The service device.

<body>
<form method= "POST" action= "/hosp/asp/register.asp" ><P>
<H2> for easy identification, please register a user name </H2>
User: <input type= "TEXT" name= "name" size= "><P>"
Password: <input type= "password" name= "password" size= "><P>"
<input type=submit value= "register" >
<input type=reset value= "Clear" >
<a href= "/hosp/asp/dispbbs.asp" > Return forum </a><P>
</body>

2, user registration (server-side) Register.asp: Use Request.Form ("form field name") to receive form information, using ADO technology and database Author.mdb connection, and the form information into the Author.mdb.

<body>
<!--the username and password entered in the client's browser-->
<% Name=request. FORM ("name")
Code=request. FORM ("password")
<!--connection with Author.mdb-->
Set connection=server.createobject ("ADODB. Connection ")
Connection.Open "Author"
Set Rs=connection.execute ("SELECT * from author")
<!--if the username already exists, please lose it or save it in the database-->
If not RS. EOF Then%>
The username has been registered, please <a href= "/hosp/login.htm" > Register </a> new username!
<% Else
Connection.Execute ("INSERT into author (authname,password) Values (' &name&" ', ' "&code&") ")
Rs. Close
Connection.close%>
<center><b><% =name%></b> You have registered successfully!<p>
<a href= "/hosp/asp/dispbbs.asp" > Return forum </a></CENTER>
<% End If%>
</body>


3, add posts (browser-side) bbs_add.htm: User input to be added to the information related to the post, and uploaded to the server.


<body background= "/hosp/images/backgrnd.gif" >
<form method= "POST" action= "/hosp/asp/bbs.asp" ><P>
Name: <input name= "name" size= "> Password: <input type=" password "name=" code "size=" "><P>
Theme: <input name= "Subject" size= "><P>"
Content:<p>
<textarea name= "Content" rows=20 cols=72></textarea><p>
<center><input type=submit value= "Release info" >
<input Type=reset value= "Clear Info" ></CENTER>
</FORM>
</body>

4, add post (server side) Bbs.asp: Receive post content, and deposit in Bbs.mdb.

<body>
<% Name=request. FORM ("name")
Code=request. FORM ("code")
Subject=request. FORM ("Subject")
Content=request. FORM ("content")
Curdate=date
Curtime=time
<!--connection with Author.mdb-->
Set Connection = Server.CreateObject ("ADODB. Connection ")
Connection.Open "Author"
Set RS = Connection.Execute ("SELECT * from author WHERE authname= '" &name& "' and password= '" &code& ' ")
<!--determine if the user name and password match-->
If not RS. EOF Then
<!--Open the data file, which holds the number of posts, each add a post, number plus 1-->
Set FileObject = Server.CreateObject ("Scripting.FileSystemObject")
Set instream = Fileobject.opentextfile ("C:inetpubwwwroothospaspdata.id", 1, false, False)
Number = Cstr (instream.readline+1)
Set OutStream = Fileobject.createtextfile ("C:inetpubwwwroothospaspdata.id", True, False)
Outstream.writeline number
If request.querystring ("ID") = "" Then
Manswernum=number
Else
Manswernum=request.querystring ("ID")
End If
If request.querystring ("topnum") = "" Then
Mtopnum=number
Else
Mtopnum=request.querystring ("Topnum")
End If
Set OutStream = Nothing
<!--connect with Bbs.mdb and deposit post information into the database-->
Set Connbbs = Server.CreateObject ("ADODB. Connection ")
Connbbs.open "BBS"
Connbbs.execute (INSERT into BBS (id,authname,subject,content,adddate,addtime,answernum,topnum,visitnum) Values (' " &number& "', '"
&name& ', ' &subject& ', ' ' &content& ', ' ' &curdate& ' ', ' ' &curtime& ', ' ', ' amp;manswernum& "', '" &mtopnum& "', 0")
Connbbs.close%>
<% =curdate & ""%><% =curtime & "Add posts"%>
<a href= "http://nt-server/hosp/asp/dispbbs.asp" > Return forum </a><P>
Name: <% =name%><p>
Topic: <% =subject%><p>
Content: <% =content%><p>
<% Else%>
Your username or password is wrong, please lose again!
<% End If
Rs. Close
Connection.close%>
</body>

5, the post specific content display and reply detail.asp


<body background= "/hosp/images/backgrnd.gif" >
<% idnum=request.querystring ("ID")
Set connection=server.createobject ("ADODB. Connection ")
Connection.Open "BBS"
Set Rs=connection.execute ("select * from BBS WHERE id= '" &idnum& "")%>
Name: <% =rs (1)%><p>
Topic: <% =rs (2)%><p>
Content: <% =rs (3)%><p>
<! --form a reply form-->
<% resub= "Re:" & RS (2)
Mtopnum=rs (8)
Rs. Close
Connection.close%>
<form method= "POST" action= "/hosp/asp/bbs.asp?id=<% =idnum%>&topnum=<% =mtopnum%>" ><P>
Name: <input name= "name" size= "> Password: <input type=" password "name=" code "size=" "><P>
Theme: <input name= "Subject" size= "value=" <% =resub%> "><P>
Content:<p>
<textarea name= "Content" rows=20 cols=72></textarea><p>
<center><input type=submit value= "information reply" >
<input Type=reset value= "Clear Info" ></CENTER>
</FORM>
<a href= "http://nt-server/hosp/asp/dispbbs.asp" > Return forum </a>
</body>

6, all posts display dispbbs.asp: List all the posts of the theme, author, time, the number of visitors and other information.


<body background= "/hosp/images/backgrnd.gif" >
<center></center><p>
<center><a href= "/hosp/login.htm" ></A>
<a href= "/hosp/bbs_add.htm" ></a>
<a href= "/hosp/default.htm" ></a></center>< P>
<% Set connection=server.createobject ("ADODB. Connection ")
Connection.Open "BBS"
Set Rs=connection.execute ("select * from BBS WHERE id=answernum order by ID DESC")
Set conn=server.createobject ("ADODB. Connection ")
Conn.Open "BBS"
Set Rsnext=conn.execute ("SELECT * from BBS")
Do but not RS. EOF%>
<% =rs (0)%> <a href= "/hosp/asp/detail.asp?id=<% =rs (0)%>" ><% =rs (2)%></a>-<FONT Size= "4" ><b><% =rs (1)%></b></font> <%
=rs (4) & ""%><% =rs (7)%> (<% =rs (5)%>) <P>
<% Set Rsnext=conn.execute ("SELECT * from BBS WHERE topnum<>id and opnum= '" &rs (0) & "' ORDER by ID ASC")
Do as not rsnext. EOF%>
<% =rsnext (0)%> <a href= "/hosp/asp/detail.asp?id=<% =rsnext (0)%>" >re<% RSNEXT (6)%>:<% = Rsnext (2)%></a>
-<font size= "4" ><b><% =rsnext (1)%></b></font> <% =rsnext (4) & ""%><% = Rsnext (7)%> (<% =rsnext (5)%>) <P>
<% Rsnext. MoveNext
Loop
Rs. MoveNext
Loop
Rsnext. Close
Conn.close
Rs. Close
Connection.close%>
</body>
The above procedures are implemented on win NT4.0 and IIS3.0.

Related Article

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.