一、建立文件
1、数据库,用来储存发表的帖子!-------命名为:bbs.mdb
2、有数据库就必须连接数据库,该文件用来连接数据库:----命名为:conn.asp
3、发表帖子的文件----命名为:say.asp
4、保存发表帖子内容的文件-----命名为:save.asp
5、显示帖子标题的文件------命名为:index.asp
6、显示帖子内容的文件,即点击标题后所进入的页面-----命名为:show.asp
7、删除帖子内容的文件-----命名为:del.asp
8、修改帖子内容的文件-----命名为:modify.asp
9、修改后保存帖子内容的文件-----命名为:modifysave.asp
10、保存回复内容------wback.asp
11、CSS样式表文件------main.css
12、页面上部----header.htm
13、页面下部------footer.htm
二、各文件的主要内容
1、bbs.mdb
打开这个数据库,就是Access建立三个表
bbs:
id(自动给帖子编号),他的数据类型设为“自动编号”
name(用来储存发表的作者),数据类型为“文本”
title(用来储存帖子的主题),数据类型为“文本”
body(用来储存帖子的内容),数据类型为“备注”
wtime(撰写时间) 时间
countwb(回复计数) 整数
bbbs:回复数据保存
hostid(楼主ID) 文本
btime(回复时间) 时间
bname(回复人名字)文本
bid(回复文章ID)数字
bcontent(回复内容)备注
btitle(回复主题) 文本
author:
name(名字)文本
code(密码)文本
sex(性别)文本
birth(出生)文本
com(联系方式)文本
2、conn.asp
源代码为:
<%Server.scriptTimeout="10"
connstr="DBQ="+server.mappath("bbs.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=Server.CreateObject("ADODB.connection")
conn.open connstr%>
建立连接,"bbs.mdb"是刚建立的数据库文件。
3、say.asp
<!--#include file="header.htm"-->
<%sub saysth()
name=request.QueryString("name")%>
<br>
<form method="post" action="save.asp" ID="Form1" >
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse: collapse; " bordercolor="#000000"
width=600 height="20" align=center ID="Table1">
<tr><td height="30">
<b>发表文章:</b><br>
大名:<input type="text" name="name" size="23" value=<%=name%>>
密码:<input type="password" name="code" size="28" ID="Password1" style="font-size:12px">
点此<a href="register.asp">注册</a><br>
标题:<input type="text" name="title" size="67" ID="Text2"><br>
内容:<br>
<textarea rows="11" name="body" cols="72" ID="Textarea1"></textarea>
<br>
<input type="submit" value="提交" name="B1" ID="Submit1"><input type="reset" value="重置" name="B2" ID="Reset1">
<input type="hidden" name="name_b" size="20" ID="Hidden1"> <input type="hidden" name="title_b" size="28" ID="Hidden2">
</td></tr>
</table>
</form>
<% end sub
'用过程和函数调用的方式,能容易理解。
'这里只是一个表单提交(到save.asp)
%>
<html>
<head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>发表</title>
</head>
<body>
<table width="770" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%saysth()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
4、save.asp
<!--#include file="conn.asp"-->
<!--#include file="header.htm"-->
<%sub save()
name=Replace(Request.Form("name"),"'","''")
title=Replace(Request.Form("title"),"'","''")
body=Replace(Request.Form("body"),"'","''")
code=Replace(Request.Form("code"),"'","''")
set savebbs=conn.execute("select * from author where name='" &name& "' " & "and code='" &code& "'" )
if name="" or title="" or body="" or code="" or savebbs.eof then%>
<br>
请<a href="history.go(-1)">后退</a>填写完整资料/填写正确用户名和密码,你才能发表帖子!<br><br>
点此<a href="register.asp">注册</a>
<%else
sql="insert into bbs(name,title,body,wtime,countwb)values('"& name & "','"&title&"','"&body& "','" & now() & "', 0)"
set savebbs=conn.execute(sql)
set savebbs=nothing
set savebbs=conn.execute("select * from bbs where name='" & name & "' order by wtime desc")
'打开数据表,插入数据。%>
<br>
发表成功!<a href="show.asp?id=<%=savebbs("id")%>">查看帖子</a> |<a href="index.asp">返回论坛</a>
<%end if
set savebbs=nothing
end sub
%>
<html>
<head>
<link href="main.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>保存</title>
</head>
<body>
<table width="770" border="0" cellspacing="0" align="center" ID="Table3">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%save()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
5、index.asp
源代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"-->
<!--#include file="header.htm"-->
<%sub maintalk()%>
<%
set showbbs = server.CreateObject("ADODB.recordset")
showbbsStr="select*from bbs order by wtime desc"
showbbs.open showbbsStr,conn,3,2
if showbbs.EOF and showbbs.BOF then%>
<br><center>暂时还没有文章,现在<a href="say.asp">发表</a></center>
<%else
showbbs.PageSize=10'分页
PageN=10 '显示10个页数.
PageCount=showbbs.PageCount
Page=int(request("Page"))
CurrentPageN=int(request("CurrentPageN"))
if Page<=0 or request("Page")="" or request("Page")="0" then Page=1
if CurrentPageN<=0 or request("CurrentPageN")="" then CurrentPageN=1
showbbs.AbsolutePage=Page
%>
<br>
<%for i=1 to showbbs.PageSize%>
<div id="arttitle">
<a href="show.asp?id=<%=showbbs("id")%>"><%=showbbs("title")%></a><br><br>
</div>
<div id="authorn">
作者:<a href="authordetail.asp?auname=<%=showbbs("name")%>"><%=showbbs("name")%></a>
<%if showbbs("countwb")=0 then%>
回复<<%=showbbs("countwb")%>><!--回复条数 -->
<%else%>
<a href="show.asp?id=<%=showbbs("id")%>">
回复<<font color=#ff0000><b><%=showbbs("countwb")%></b></font>>
</a><!--回复条数 -->
<%end if%>
<%wt=showbbs("wtime")'如果为撰写当天的时间,红色显示。
if year(now())=year(wt) and month(now())=month(wt) and day(now())=day(wt) then%>
撰写/修改时间:<font color=#ff0000><%=wt%></font>
<%else%>
撰写/修改时间:<%=wt%>
<%end if%>
<a href="modify.asp?id=<%=showbbs("id")%>">修改</a>
<a href="del.asp?id=<%=showbbs("id")%>">删除</a>
</div>
<hr size="1" width=600 align="left" style=" border:dashed #999999 ">
<%showbbs.movenext
if showbbs.EOF then exit for
Next%>
<center>
<br>
<%'以下为页码显示。
if Page<>1 then%>
<a href="index.asp?Page=1&CurrentPageN=1">(首页)</a>
<%else%>
(当前为首页)
<%end if%>
<%if PageCount>PageN and CurrentPageN>=2 then%>
<a href="index.asp?Page=<%=(CurrentPageN-2)*PageN+1%>&CurrentPageN=<%=CurrentPageN-1%>">(上<%=PageN%>页)</a>
<%end if%>
<%for i=(CurrentPageN-1)*PageN+1 to (CurrentPageN-1)*PageN+PageN%>
<%if i = Page then%>
<font color=#ff0000 >-<%=i%>-</font>
<%elseif i<showbbs.RecordCount/showbbs.PageSize +1 then%>
<a href="index.asp?page=<%=i%>&CurrentPageN=<%=CurrentPageN%>"> <%=i%> </a>
<%end if%>
<%Next%>
<%if PageCount>PageN and CurrentPageN<PageCount/PageN then%>
<a href="index.asp?Page=<%=CurrentPageN*PageN+1%>&CurrentPageN=<%=CurrentPageN+1%>">(下<%=PageN%>页)</a>
<%end if%>
<%if PageCount>PageN and Page<>PageCount then%>
<a href="index.asp?Page=<%=PageCount%>&CurrentPageN=<%=int(PageCount/PageN)+1%>">(最后一页)</a>
<%end if%>
<%if PageCount=Page then%>(当前为最后页)<%end if%>
(共<%=PageCount%>页)
</center>
<%showbbs.Close
set showbbs=nothing
end if
end sub%>
<!------------------------------------------------- -->
<%sub saysth()
'下方的快捷发表表单
name=request.QueryString("name")%>
<hr size="1" width=700>
<form method="post" action="save.asp">
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse: collapse; "
width=600 align=center>
<tr><td>
发表文章:<br>
大名:<input type="text" name="name" size="23" value=<%=name%>>
密码:<input type="password" name="code" size="28" ID="Password1" style="font-size:12px">
点此<a href="register.asp">注册</a><br>
标题:<input type="text" name="title" size="67" ID="Text2"><br>
内容:<br>
<textarea rows="11" name="body" cols="72" ID="Textarea1"></textarea>
<br>
<input type="submit" value="提交" name="B1" ID="Submit1"><input type="reset" value="重置" name="B2" ID="Reset1">
<input type="hidden" name="name_b" size="20" ID="Hidden1"> <input type="hidden" name="title_b" size="28" ID="Hidden2">
</td></tr>
</table>
</form>
<%end sub%>
<!----------------------------------------------------------- -->
<html><head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>讨论区首页</title></head>
<body>
<table width="770" border="0" cellspacing="0" align="center">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%maintalk()%><%saysth()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
6、show.asp
源代码:
<!--#include file="conn.asp"-->
<!--#include file="header.htm"-->
<%id=request.querystring("id")
set show=conn.execute("select*from bbs where id="&id&"")'全局%>
<%sub maintalk
'主文章%>
<br>
<div id="arttitle">
<%=show("title")%><br><br>
</div>
<div id="authorn">
作者:<a href="authordetail.asp?auname=<%=show("name")%>"><%=show("name")%></a>
撰写/修改时间:<%=show("wtime")%>
<a href="modify.asp?id=<%=show("id")%>">修改</a>
<a href="del.asp?id=<%=show("id")%>">删除</a>
</div>
<table border="0" id="content_table"><tr><td>
<div id="content"><b>内容:</b><%=show("body")%></div>
</td></tr></table>
<br><hr size="1" width=700 align="left">
<%end sub%>
<%sub wbtalk()
'回复文章%>
<%sql="select*from bbbs where hostid='" & id & "' order by btime asc"
set showwback=conn.execute(sql)
floori=0
do while not showwback.eof '没有像主页那样分页,原理相同。
floori=floori+1%>
<div id="arttitle">
<%=floori%>楼:<%=showwback("btitle")%><br><br>
</div>
<div id="authorn">
回复人:<a href="authordetail.asp?auname=<%=showwback("bname")%>"><%=showwback("bname")%></a>
回复时间:<%=showwback("btime")%>
</div>
<table border="0" id="content_table"><tr><td>
<div id="content"><b>回复内容:</b><%=showwback("bcontent")%></div>
</td></tr></table>
<br>
<!--<hr size="1" width=600 align=left style=" border:dashed #999999 "> -->
<%showwback.movenext
Loop
set showwback=nothing
end sub%>
<%sub wbform()
'回复表单 提交到第10个文件wback.asp中%>
<br><hr size="1" width=700 align=center>
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse: collapse; " bordercolor="#000000"
width=600 height="20" align=center ID="Table1">
<tr><td>
<form method="POST" action="wback.asp" >
回 复 人:<input type="text" name="name_b" size="20">
密码:<input type="password" name="code_b" size="20" style="font-size:12px">
点此<a href="register.asp">注册</a><br>
<input type="hidden" name="id_h" size="20" value= <%=id%> />
回复标题:<input type="text" name="title_b" size="70" value="re:<%=show("title")%>"><br>
回复内容:<br>
<textarea rows="11" name="body_b" cols="80"></textarea><br>
<br>
<input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2">
</form>
</td></tr></table>
<%end sub%>
<html><head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>查看帖子</title>
</head>
<body>
<table width="770" border="0" cellspacing="0" align="center">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%maintalk()%><%wbtalk()%><%wbform()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
7.del.asp
源代码:
<!--#include file="conn.asp"-->
<!--#include file="header.htm"-->
<%sub del()
name=request.querystring("hostname")
code=request.Form("code")'要求密码确认。
id=request.querystring("id")
if code="" and id<>"" then%>
<FORM METHOD="post" ACTION="del.asp?id=<%=id%>" ID="Form1">
<%set rsname=conn.execute("select * from bbs where id=" & id)%>
<br>
将要删除 <%=rsname("name")%> 的大作: <%=rsname("title")%><br /><br />
连同文章的回复都将被删除!<br><br />
作者密码:<INPUT TYPE="password" name="code" SIZE="28" ID="Password1" style="font-size:12px">
<INPUT TYPE="submit" VALUE="删除" ID="Submit1" NAME="Submit1">
</FORM>
<%elseif id="" then%>
还没有选择帖子,<a href="index.asp">返回首页</a>选择一个帖子删除
<%else
set rsname=conn.execute("select * from bbs where id=" & id)
set rs=conn.execute("select * from author where name='" &rsname("name")& "' and code= '" &code& "'")
if not rs.eof then
conn.execute("Delete from bbs where id="&id&" ")
conn.execute("delete from bbbs where hostid='"&id&"'")%>
<br>
<center>删除成功!<a href="index.asp">查看帖子</a></center>
<%else%>
<br>
用户名或密码错误!<a href= "del.asp?id=<%=id%>">返回</a>继续操作.<br>
<a href="index.asp">返回首页</a>
<%end if
set rs=nothing
set rsname=nothing
end if
end sub%>
<html><head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>删除</title></head>
<body>
<table width="770" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%del()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
8.modify.asp
修改:
<!--#include file="header.htm"-->
<%sub modify()
id=request.querystring("id")
set show=conn.execute("select*from bbs where id="&id&"")%>
<br>
<table border="0" cellpadding="0" cellspacing="0"
style="border-collapse: collapse; "
width=600 align=center>
<form method="POST" action="modifysave.asp">
<tr><td>
<br>
<input type="hidden" name="id" value=<%=show("id")%> size="20"><!--不要修改这个! -->
<input type="hidden" name="name" value=<%=show("name")%> size="20"><p>
大名:<%=show("name")%> 密码:<input type="password" name="code" size="20" style="font-size:12px"><br>
标题:<input type="text" name="title" value=<%=show("title")%> size="76"><br>
内容:<br>
<textarea rows="11" name="body" cols="80"><%=show("body")%></textarea><br>
<input type="submit" value="修改" name="B1"><input type="reset" value="重置" name="B2"><p>
</td></tr>
</form>
</table>
<%set show=nothing
end sub%>
<html><head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>修改</title></head>
<body>
<table width="770" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%modify()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
9.modifysave.asp
modify.asp链接到的文件:
源代码:
<!--#include file="conn.asp"-->
<!--#include file="header.htm"-->
<%sub modifysave()
id=Replace(Request.Form("id"),"'","''")
name=Replace(Request.Form("name"),"'","''")
code=Replace(Request.Form("code"),"'","''")
title=Replace(Request.Form("title"),"'","''")
body=Replace(Request.Form("body"),"'","''")
set savebbs=conn.execute("select * from author where name='" &name& "' and code= '" &code& "'")
if name="" or title="" or body="" or savebbs.eof then%>
<br>
修改帖子失败!<br><br>
请<a href="history.go(-1)">后退</a>填写完整资料/填写正确用户名和密码,你才能发表帖子!<br><br>
点此<a href="register.asp">注册</a>
<%else
conn.execute("update bbs set title='" &title& "' where id=" &id)
conn.execute("update bbs set body='" &body& "' where id=" &id)
conn.execute("update bbs set wtime='" &now()& "' where id=" &id)%>
<br>
修改成功!<a href="show.asp?id=<%=id%>">查看帖子</a>
<a href="index.asp">回到首页</a>
<%end if
set savebbs=nothing
end sub%>
<html><head>
<link href="main.css" rel="stylesheet" type="text/css" />
<title>保存修改</title></head>
<body>
<table width="770" border="0" cellspacing="0" cellpadding="0" align="center" ID="Table3">
<tr>
<td id="tbul"> </td>
<td id= "tbum"><%headtext()%></td>
<td id="tbur"> </td>
</tr>
<tr>
<td id="tbml"> </td>
<td id="tbmm"><%modifysave()%></td>
<td id="tbmr"> </td>
</tr>
<tr>
<td id="tbll"> </td>
<td id="tblm"> </td>
<td id="tblr"> </td>
</tr>
</table>
<!--#include file="footer.htm"--></body>
</html>
10、wback.asp
源代码:
<!--#include file="conn.asp"-->
<link href="main.css" rel="stylesheet" type="text/css" />
<%
idh=Replace(Request.Form("id_h"),"'","''")
nameb=Replace(Request.Form("name_b"),"'","''")
titleb=Replace(Request.Form("title_b"),"'","''")
bodyb=Replace(Request.Form("body_b"),"'","''")
codeb=Replace(Request.Form("code_b"),"'","''")
set rs=conn.execute("select * from author where name='" &nameb& "' and code='" &codeb& "'")
sql="select * from author where name='" &nameb& "' and code='" &codeb& "'"
if nameb="" or titleb="" or bodyb="" or idh="" or rs.eof then%><title>回复保存</title>
有数据为空/错误的用户名或密码!<a href="show.asp?id=<%=idh%>">查看帖子</a>,点此<a href="register.asp">注册</a>
<%else
sql="update bbs set countwb=countwb+1 where id=" &idh
conn.execute(sql)
sql="insert into bbbs(hostid,btime,bname,bcontent,btitle) " & _
"values('"& idh & "','" & now() &"','"& nameb &"','"& bodyb &"','"& titleb &"')"
conn.execute(sql)%>
发表成功!<a href="index.asp">回到首页</a> <br>
<a href="show.asp?id=<%=idh%>">查看帖子</a>
<%response.Redirect("show.asp?id="&idh)'这里用了直接跳转。可在这儿停下,给出提示。
end if %>
11、main.css
美化页面:CSS样式表文件:
BODY {FONT-SIZE: 14px; MARGIN: 30px}
TD {FONT-SIZE: 14px}
A:link {COLOR: #000088; TEXT-DECORATION: none}
A:visited {COLOR: #000088; TEXT-DECORATION: none}
A:hover {COLOR: #ff0000; TEXT-DECORATION: underline}
A:active {COLOR: #000000; TEXT-DECORATION: none}
#tbul{
background:url(images/ball.gif) center left no-repeat;
width:24px;
border-left:1px #83B4F2 solid;
border-top:1px #83B4F2 solid;
border-bottom:1px #83B4F2 solid;
}
#tbum{
width:728px;
border-top:1px #83B4F2 solid;
border-bottom:1px #83B4F2 solid;
}
#tbur{
width:19px;
border-right:1px #83B4F2 solid;
border-top:1px #83B4F2 solid;
border-bottom:1px #83B4F2 solid;
}
#tbml{
border-left:1px #83B4F2 solid;
}
#tbmm{
}
#tbmr{
width:19px;
border-right:solid #83B4F2 1px;
}
#tbll{
border-bottom:1px #83B4F2 solid;
border-left:1px #83B4F2 solid;
width:19px;
}
#tblm{
border-bottom:1px #83B4F2 solid;
}
#tblr
{background:url(images/coner.gif) bottom right no-repeat;
border-top:1px #83B4F2 solid;
border-left:1px #83B4F2 solid;
width:19px;
height:19px;
}
#authorn{
font-size:12px;
padding-bottom:4px;
}
#head{
color:#0033FF;
line-height:24px;
vertical-align:middle;
padding-top:2px;
padding-left:3px;
}
#arttitle{
color:#0000FF;
font-size:14px;
font-weight:bold;
background:url(images/mainar.gif) top left no-repeat;
padding-left:23px;
padding-top:4px;
padding-bottom:0px;
}
#content{
padding: 9px 5px 5px 5px;
font-size:15px;
}
#content_table
{
border:dotted 1px #83B4F2;
border-left:solid 2px #83B4F2;
width:670px;
}
12、header.htm
页面上部:
<link href="main.css" rel="stylesheet" type="text/css" />
<% function headtext()%>
<div id="head">
<a href="index.asp">回到首页</a>|
<a href="register.asp">一站注册</a>|
<a href="say.asp">发表帖子</a>
</div>
<%end function%>
13、footer.htm
页面下部:
<center>
<br>
<br>
<font style="FONT-SIZE: 12px; COLOR: #6699ff; BACKGROUND-COLOR: transparent" >保留版权2006-2007</font>
</center>
14、图片(超链接到了我的相册中):