ASP network Programming: Using ASP to realize Web BBS

Source: Internet
Author: User

Most of the traditional Web BBS is implemented by CGI, which requires programmers to master programming languages such as Perl or C, but also to understand the CGI mode of the various technical content, so to make their own web BBS is really difficult. The presence of ASP (Active Server Pages Dynamic Servers home page) makes us bright, can we use ASP to implement Web BBS? The answer is of course affirmative. The tempting thing about ASP is that it provides a simple and easy-to-learn script with many built-in objects, providing a straightforward way to program. "Shanghai Treatment Impotence Hospital"
The BBS mainly by the user registration (browser side), user registration (server side), add posts (browser side), add posts (server side), the display and reply of the specific content of the post and all the posts display six parts, Where the user information is stored in the database Author.mdb, the post is stored in the database Bbs.mdb. They are all Access databases, as shown in table 1 and table 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 Topics
Content Comment Contents
Adddate Date/Time affixed date
Visitnum number of long-integer visitors
Answernum Text 4 The number of the post that was replied to
(Default is the number of itself)
Addtime Date/Time add-on time
Topnum Text 4 Number of first-level reply post
The implementation method is as follows, where ASP files and databases are stored in "/hosp/asp", other HTM
The file is stored in the "/hosp" file, and the img file is stored in "/hosp/images".
1, user registration (browser-side) login.htm: User input related information, through the form to the service
Service.
<body>
<form method= "POST" action= "/hosp/asp/register.asp" > <p>
Users: <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 to forum </a> <p>
</body>
2, user registration (server side) Register.asp: Using 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>
!--user name and password entered by the customer'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 user name already exists, please re-lose it, otherwise deposit the database-->
If not RS. EOF then%>
This user name has been registered, please re-<a Href= "/hosp/login.htm" > Register the </a> new username!
<% Else
Connection.Execute ("INSERT into author (authname,password) Values ('" &name& "', '" &code& ') ")
Rs. Close
Connection.close%>
<CENTER> <B> <% =name%> </B> you are registered successfully! <p>
<a Href= "/hosp/asp/dispbbs.asp" > Return to forum </a> </CENTER>
<% End If%>
</body>
3, add posts (browser-side) bbs_add.htm: User input to join the post information, and upload to the server.
<body background= "/hosp/images/backgrnd.gif" >
<form method= "POST" action= "/hosp/asp/bbs.asp" > <p>
Name: <input name= "name" size= "28" > password: <input type= "password" name= "code" size= "page" > <p>
Theme: <input name= "Subject" size= "the" "<p>"
Content: <p>
<textarea name= "Content" rows=20 cols=72> </TEXTAREA> <p>
<CENTER> <input type=submit value= "Release information" >
<input Type=reset value= "Clear info" > </CENTER>
</FORM>
</body>
4, add posts (server side) Bbs.asp: Receive post content, and deposited 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, the file holds the number of the post, each add a post, number plus 1-->
Set FileObject = Server.CreateObject ("Scripting.FileSystemObject")
Set instream = Fileobject.opentextfile ("C:\inetpub\wwwroot\hosp\asp\data.id", 1, false, False)
Number = Cstr (instream.readline+1)
Set OutStream = Fileobject.createtextfile ("C:\inetpub\wwwroot\hosp\asp\data.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 to store post information in 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 to forum </a> <p>
Name:% =name%> <p>
Subject:% =subject%> <p>
Content:% =content%> <p>
<% Else%>
Your user name or password error, please re-lose!
<% End If
Rs. Close
Connection.close%>
</body>
5, the post specific content display and the 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>
Subject:% =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= "28" > password: <input type= "password" name= "code" size= "page" > <p>
Subject: <input name= "Subject" size= "the" The Value= "<% =resub%>" > <p>
Content: <p>
<textarea name= "Content" rows=20 cols=72> </TEXTAREA> <p>
<CENTER> <input type=submit value= "message reply" >
<input Type=reset value= "Clear info" > </CENTER>
</FORM>
<a Href= "http://nt-server/hosp/asp/dispbbs.asp" > Back to forum </a>
</body>
6. Display of all posts dispbbs.asp: Lists the subject, author, time, number of visitors and other information for all posts.
<body background= "/hosp/images/backgrnd.gif" >
<CENTER> <CENTER> A href= "/hosp/login.htm" > <a Href= "/hosp/bbs_add.htm" > <a Href= "/hosp/default.htm" > <% Set Connectio N=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 and 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 and 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.

ASP network Programming: Using ASP to realize Web BBS

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.