|
4、 加帖子(服务器端)bbs.asp:接收帖子内容,并存入bbs.mdb中。
<html> <head><title>bbs.asp</title></head> <body> <% name=REQUEST.FORM("name") code=REQUEST.FORM("code") subject=REQUEST.FORM("subject") content=REQUEST.FORM("content") curdate=Date curtime=Time <!-- 与author.mdb连接 --> Set Connection = Server.CreateObject("ADODB.Connection") Connection.Open "author" Set RS = Connection.Execute("SELECT * FROM author WHERE authname='" &name& "' AND password='" &code& "'") <!-- 判断用户名与密码是否匹配 --> If Not RS.EOF Then <!-- 打开数据文件,该文件存放帖子的编号,每加一个帖子,编号加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 <!-- 与bbs.mdb连接,将帖子信息存入数据库中 --> 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& "','" &manswernum& "','" &mtopnum& "',0)") Connbbs.Close %> <% =curdate & " " %><% =curtime & " 添加贴子 " %> <a href="http://nt-server/hosp/asp/dispbbs.asp">返回论坛</a><P> 姓名:<% =name %><P> 主题:<% =subject %><P> 内容:<% =content %><P> <% Else %> 您的用户名或密码出错,请您重输! <% End If RS.Close Connection.Close %> </body> </html>
5、帖子具体内容的显示和回复 detail.asp
<html> <head><title>bbs.asp</title></head> <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& "'") %> 姓名:<% =RS(1) %><p> 主题:<% =RS(2) %><p> 内容:<% =RS(3) %><p>
------------------------------------------------------------------------------ <! --形成回复表单 --> <% resub="Re:" & RS(2) mtopnum=RS(8) RS.Close Connection.Close %> <FORM METHOD="POST" ACTION="/hosp/asp/bbs.asp?ID=<% =idnum %>&topnum=<% =mtopnum %>"><P> 姓名: <INPUT NAME="name" SIZE="28"> 密码: <INPUT TYPE="password" NAME="code" SIZE="28"><P> 主题:<INPUT NAME="subject" SIZE="66" VALUE="<% =resub %>"><P> 内容:<P> <TEXTAREA NAME="content" ROWS=20 COLS=72></TEXTAREA><P> <CENTER><INPUT TYPE=SUBMIT VALUE="信息回复"> <INPUT TYPE=RESET VALUE="清除信息"></CENTER> </FORM> <a href="http://nt-server/hosp/asp/dispbbs.asp">返回论坛</a> </body> </html>
6、所有帖子的显示 Dispbbs.asp:列出所有的帖子的主题、作者、时间、访问人数等信息。
<html> <head><title>dispbbs.asp</title></head> <body background="/hosp/images/backgrnd.gif"> <CENTER><IMG SRC="/hosp/images/luntan.gif" BORDER=0></CENTER><P> <CENTER><A HREF="/hosp/login.htm"><IMG SRC="/hosp/images/zhuce.gif" BORDER=0></A> <A HREF="/hosp/bbs_add.htm"><IMG SRC="/hosp/images/jiatz.gif" BORDER=0></A> <A HREF="/hosp/default.htm"><IMG SRC="/hosp/images/return.gif" BORDER=0></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 While 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 While 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> </html>
上述程序在Win NT4.0和IIS3.0上实现通过。
上一页 [1] [2]
|