魅力博客

魅力Linux|魅力空间|魅力博客|学习Linux|ubuntu日记|电脑教程|手机软件

5分钟编写一个简单ASP小论坛系统



学ASP朋友的。。给大家分享个好东西
真NB..佩服ing .....
大家在网上看到各种各样的ASP论坛是不是觉的做论坛很难呢,其实我们用简单的ASP语句就完全可以完成一个属于自己的论坛。下面我教大家如何用ASP来打造一个属于自己的论坛,自己的东西毕竟用起来爽吗。

同时,再复杂的论坛的写成也离不开下面的基本步骤,大家仔细看了。

一、建立文件!
最简单的论坛也要有几个必要的文件,就是:

1、数据库,用来储存发表的帖子!-------命名为:bbs.mdb

2、有数据库就必须连接数据库,该文件用来连接数据库:----命名为:conn.asp

3、发表帖子的文件----命名为:say.asp

4、保存发表帖子内容的文件-----命名为:save.asp

5、显示帖子标题的文件------命名为:index.asp

6、显示帖子内容的文件,即点击标题后所进入的页面-----命名为:show.asp

建立文件是可以先建立文本文档,他的格式为"文件名.txt",我们只需把它改为"文件名.asp"

二、各文件的主要内容

1、bbs.mdb

打开这个数据库,建立一个表,命名为bbs

该表中有几个字段:

id(自动给帖子编号),他的数据类型设为“自动编号”

name(用来储存发表的作者),数据类型为“文本”

title(用来储存帖子的主题),数据类型为“文本”

body(用来储存帖子的内容),数据类型为“备注”

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
%>

这个文件就是这样,代码内容大家就自己研究,这个我也不知道怎么说才好!

3、say.asp

源代码为:
<form method="POST" action="save.asp">
<p>大名:<input type="text" name="name" size="20"></p>
<p>标题:<input type="text" name="title" size="91"></p>
<p>内容:</p>
<p><textarea rows="11" name="body" cols="97"></textarea></p>
<p> </p>
<p><input type="submit" value="提交" name="B1"><input type="reset" value="重置" name="B2"></p>
</form>
大家应该看得懂的,这个根本就是html语法,对的,根本就是,这个只是发表的界面
不过要注意这一句<form method="POST" action="save.asp">,他把用户所填的内容发送至save.asp这个文件,下面就看save.asp这个文件吧!

4、save.asp

源代码:
<!--#include file="conn.asp"-->
<%name=Replace(Request.Form("name"),"'","''")
title=Replace(Request.Form("title"),"'","''")
body=Replace(Request.Form("body"),"'","''")
%>
<%if name="" or title="" or body="" then%>
请<a href="****:history.go(-1)">后退</a>填写完整资料,你才能发表帖子!
<%else%>
<%set savebbs=conn.execute("insert into bbs(name,title,body)values('"&name&"','"&title&"','"&body&"')")%>
发表成功!<a href="index.asp">查看帖子</a>
<%end if
set savebbs=nothing
%>

第一句:<!--#include file="conn.asp"-->,意思是插入conn.asp文件,即与数据库进行连接!
asp语句必须用<% %>这个格式包含起来,而插入文件的语句就不用,
接下来几句:
name=Replace(Request.Form("name"),"'","''")
title=Replace(Request.Form("title"),"'","''")
body=Replace(Request.Form("body"),"'","''")

“Replace(Request.Form("name"),"'","''")”意思是接收表单中名为name的文本框发来的数据,
而“name=Replace(Request.Form("name"),"'","''")”则是把发来的数据储存在name变量中,
如果你这样:“abc123=Replace(Request.Form("name"),"'","''")”
就是把表单中名为name的文本框发来的数据储存在abc123变量中

接着:if name="" or title="" or body="" then
判断name、title和body变量中是否没有填写内容,即为"",如果这样,就执行这一语句:
“请<a href="****:history.go(-1)">后退</a>填写完整资料,你才能发表帖子!”
该语句属于html语法,大家都看得懂的!

"<%else%>"就是说“当if……then不成立(即是说所有内容都已经填写)”,就执行语句:
“<%set savebbs=conn.execute("insert into bbs(name,title,body) values('"&name&"','"&title&"','"&body&"')")%>
发表成功!<a href="index.asp">查看帖子</a>”

"set save=conn.execute"属于固定的语句,不过savebbs可以自己修改,"="后面的就难解释了:
insert into bbs(name,title,body)意思是向名为bbs的表(在建立数据库时已经建立的表)
中的name,title,body字段插入,插入什么呢?看接下的values('"&name&"','"&title&"','"&body&"')")
values是“值”的意思
就是插入向量name,title,body,向量用格式'"&name&"'表示

最后:end if就是结束if……then
set savebbs=nothing可以说是关闭掉:
set savebbs=conn.execute("insert into bbs(name,title,body) values('"&name&"','"&title&"','"&body&"')")


5、index.asp
源代码:
<!--#include file="conn.asp"-->
<b><a href="say.asp">发表帖子</a></b><br><br>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; " bordercolor="#000000" width="100%" height="26">
<tr>
<td width="17%"><b>作者</b></td>
<td width="83%"><b>主题</b></td>
</tr>
</table>
</center>
</div><hr size="1">
<%i=1
set showbbs=conn.execute("select*from bbs order by id desc")
do while not showbbs.eof
%>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; " bordercolor="#000000" width="100%" height="20">
<tr>
<td width="17%"><%=showbbs("name")%> </td>
<td width="83%">
<a href="show.asp?id=<%=showbbs("id")%>"><%=showbbs("title")%></a></td>
</tr>
</table>
</center>
</div><hr size="1">
<%i=i+1
if i>50 then exit do
showbbs.movenext
Loop
showbbs.Close
set showbbs=nothing
%>

这个文件就不一句一句的讲了
主要讲精华部分:
set showbbs=conn.execute("select*from bbs order by id desc")
意思是:向数据库中的bbs数据表查询数据,并以id排顺序,
还有这么一句:<%=showbbs("name")%>
就是显示数据表中的name字段的数据,这里的showbbs就是set showbbs=……中的showbbs
代码中的i=1和i=i+1
if i>50 then exit do
showbbs.movenext
Loop
showbbs.Close
set showbbs=nothing

这几句属于循环语句,这里就不理他,理解了也不太好用,因为他只显示50张贴子!
if i>50 then exit do中的50可以修改
但我们做论坛必须把帖子分页,又因为分页这个语句太复杂,我想就不讲了,等这一个弄懂了才来弄
还有一句很有用的:
<a href="show.asp?id=<%=showbbs("id")%>"><%=showbbs("title")%></a>
里面的超连接:show.asp?id=<%=showbbs("id")%>,注意:这里的超连接把帖子的id包含了,
等一下在show.asp文件中就有用了

5、show.asp
源代码:

<!--#include file="conn.asp"-->
<%id=request.querystring("id")%>
<%set show=conn.execute("select*from bbs where id="&id&"")%>
<a href="index.asp">
<b>回到首页</b></a><br><b><a href="say.asp">发表帖子</a></b><br><hr size="1">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="180">
<tr>
<td width="21%" height="22"><b>作者:</b><%=show("name")%></td>
<td width="79%" height="22"><b>主题:</b><%=show("title")%></td>
</tr>
<tr>
<td width="100%" colspan="2" height="158" valign="top"><b><br>内容:</b><%=show("body")%></td>
</tr>
</table><%set show=nothing%>

劲语句---精华语句:
id=request.querystring("id")
在讲解index.asp文件的后面已经说到:show.asp?id=<%=showbbs("id")这一句,
id=request.querystring("id")就是把地址栏中的id的值读取下来,
因为index.asp文件中的超连接点击后,地址栏就为http://…………/show.asp?id=数字,
所以show.asp使用id=request.querystring("id")语句把数字读取下来
于是接着使用:set show=conn.execute("select*from bbs where id="&id&"")
向数据表查询id为这时读取下来的数字的帖子,即where id="&id&"
最后<%set show=nothing%>

好了,一个简单的论坛就这样完成了,挂在我们自己的ASP空间上去试试

asp论坛制作教程 BBS ASP源码 (对增进版的再改进)

一、建立文件
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">&nbsp;</td>
        <td id= "tbum"><%headtext()%></td>
        <td      id="tbur">&nbsp;</td>
      </tr>
      <tr>
        <td id="tbml">&nbsp;</td>
        <td id="tbmm"><%saysth()%></td>
        <td id="tbmr">&nbsp;</td>
      </tr>
  
      <tr>
        <td id="tbll">&nbsp;</td>
        <td id="tblm">&nbsp;</td>
        <td id="tblr">&nbsp;</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>&nbsp;
      <%if showbbs("countwb")=0 then%>
       回复&lt;<%=showbbs("countwb")%>&gt;<!--回复条数 -->
      <%else%>
       <a href="show.asp?id=<%=showbbs("id")%>">
       回复&lt;<font color=#ff0000><b><%=showbbs("countwb")%></b></font>&gt;
       </a><!--回复条数 -->
      <%end if%>&nbsp;
  
      <%wt=showbbs("wtime")'如果为撰写当天的时间,红色显示。
      if year(now())=year(wt) and month(now())=month(wt) and day(now())=day(wt) then%>
       撰写/修改时间:<font color=#ff0000><%=wt%></font>&nbsp;
      <%else%>
       撰写/修改时间:<%=wt%>&nbsp;
      <%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%>">&nbsp;<%=i%>&nbsp;</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>&nbsp;
撰写/修改时间:<%=show("wtime")%>&nbsp;
<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" >
回&nbsp;复&nbsp;人:<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">&nbsp;</td>
        <td id= "tbum"><%headtext()%></td>
        <td      id="tbur">&nbsp;</td>
      </tr>
      <tr>
        <td id="tbml">&nbsp;</td>
        <td id="tbmm"><%maintalk()%><%wbtalk()%><%wbform()%></td>
        <td id="tbmr">&nbsp;</td>
      </tr>
  
      <tr>
        <td id="tbll">&nbsp;</td>
        <td id="tblm">&nbsp;</td>
        <td id="tblr">&nbsp;</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>
       将要删除&nbsp;<%=rsname("name")%>&nbsp;的大作: &nbsp;<%=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">&nbsp;</td>
        <td id= "tbum"><%headtext()%></td>
        <td      id="tbur">&nbsp;</td>
      </tr>
      <tr>
        <td id="tbml">&nbsp;</td>
        <td id="tbmm"><%del()%></td>
        <td id="tbmr">&nbsp;</td>
      </tr>
  
      <tr>
        <td id="tbll">&nbsp;</td>
        <td id="tblm">&nbsp;</td>
        <td id="tblr">&nbsp;</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")%>&nbsp;密码:<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">&nbsp;</td>
        <td id= "tbum"><%headtext()%></td>
        <td      id="tbur">&nbsp;</td>
      </tr>
      <tr>
        <td id="tbml">&nbsp;</td>
        <td id="tbmm"><%modify()%></td>
        <td id="tbmr">&nbsp;</td>
      </tr>
  
      <tr>
        <td id="tbll">&nbsp;</td>
        <td id="tblm">&nbsp;</td>
        <td id="tblr">&nbsp;</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">&nbsp;</td>
        <td id= "tbum"><%headtext()%></td>
        <td      id="tbur">&nbsp;</td>
      </tr>
      <tr>
        <td id="tbml">&nbsp;</td>
        <td id="tbmm"><%modifysave()%></td>
        <td id="tbmr">&nbsp;</td>
      </tr>
  
      <tr>
        <td id="tbll">&nbsp;</td>
        <td id="tblm">&nbsp;</td>
        <td id="tblr">&nbsp;</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、图片(超链接到了我的相册中):



返回顶部

发表评论:

Powered By Z-BlogPHP 1.7.3


知识共享许可协议
本作品采用知识共享署名 3.0 中国大陆许可协议进行许可。
网站备案号粤ICP备15104741号-1