ASP留言板的设计与实现
的有关信息介绍如下:如何开发一个ASP的留言板系统呢?我们下面就来介绍一个最简单的留言板开发过程。首先一个留言板系统有发布留言信息与后台回复留言。需要用的数据库我们这里采用SQL2000。
留言板系统是一个最基本也是最常见的系统。学会了留言板的设计对以后的基他系统的开发有很好的帮助。
开始时建立数据库,我们新建一个数据库,进入企业管理器,右击数据库,选择新建数据库
输入一个数据库名称
选中新好的数据库,在右边的窗口中,右击,弹出的菜单里选新建数据表
表名:message
ID int 4
memo text 16
time1 nvarchar 50
hui text 16
id自动加1
memo是留言内容
time1留言时间
hui回复内容
添加,4个字段
然后设置ID字段为自动加1,如下图所示
新建一个站点,命名为message
新建一个文件夹在D盘,命名为留言板,把IIS的物理路径(参考aspIIS设置的那篇文章
http://jingyan.baidu.com/article/fedf0737663b3935ac8977fa.html
)设置为D:\留言板
把站点的文件路径也设为:D:\留言板
在Adobe Dreamweaver CS4 中新建文件
点击创建一个html的文档。
然后修改这个文档的编码,把编码改为GB2312。
然后在文件中删除默认的那些代码,重新输入以下新代码
下面的代码是接sql2000数据库
<%
Dim Database
Database="datamessage"
Dim Conn,ConnStr
Set conn = Server.CreateObject("ADODB.Connection")
ConnStr="Provider=sqloledb;Server=localhost;database="&Database&";uid=sa;pwd="
Conn.open ConnStr
%>
然后保存为conn.asp文件
注意选保存文件的类型为所有文件(*.*)
再次新建一个名为:default.asp的文件,这个文件是显示和添加留言的页面
编码也需要改为GB2312
在这里输入的代码如下:
<%
if request("action")="addmessagesave" then
if trim(request("memo"))="" then
Response.Write("")
response.End()
End if
set rsa=Server.CreateObject("ADODB.RecordSet")
strsqla="select * from [message]"
rsa.open strsqla,conn,3,2
rsa.addnew
rsa("memo")=request("memo")
rsa("time1")=now
rsa.update
Response.Write("")
response.End()
End if
%>
*{margin:0px;padding:0px;font-size:14px;color:#000000;}
a{font-size:14px;color:#999999;}
body{margin:0 auto;line-height:30px;}
| 留言 <% message
addmessage
%>
|
<%
sub addmessage()
%>
<%
end sub
SUB message()
set rs=Server.CreateObject("ADODB.RecordSet")
sql="select * from message order by id desc"
rs.open sql,conn,1,1
if rs.eof then
if request("key")<>"" then
response.write("
else
response.write("
End if
else
response.write("
PERPAGE=10
if request("pageno")="" or isNumeric(request("pageno"))=0 or request("pageno")<"1" then
curpage = 1
else
curpage = cint(request("pageno"))
end if
rs.pagesize = PERPAGE
if curpage>rs.pagecount then curpage=rs.pagecount
rs.absolutepage = curpage
for i=1 to rs.pagesize
if rs.eof then
exit for
end if
%>
[内容] | <%=rs("memo")%> | |
<%
%> | [时间:<%=rs("time1")%>] | |
[回复] | <%=rs("hui")%> |
<%
rs.movenext
next
if curpage = 1 then
response.write "
else
response.write "
"
else