需要动态网页开发技术,不知道你目前学的怎么样。先要架设安装IIS服务器,用来解析ASP程序,下载安装一个数据库,你可以使用SQL server数据库。
创建一个asp文件,里面创建留言标题,留言人信息,手机号,留言内容等,使用代码连接数据库,代码如下。
<%Dim Database
Database="datamessage"
Dim Conn,ConnStr
Set conn = Server.CreateObject("ADODB.Connection")
ConnStr="Provider=sqloledbServer=localhostdatabase="&Database&"uid=sapwd="
Conn.open ConnStr
%>
再次新建一个名为:default.asp的文件,这个文件是显示和添加留言的页面
编码也需要改为GB2312
在这里输入的代码如下:
<!--#include file="conn.asp"--><%
if request("action")="addmessagesave" then
if trim(request("memo"))="" then
Response.Write("<script lanuage=javascript>alert('留言内容不能为空!')location='message.asp'</script>")
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("<script lanuage=javascript>alert('留言成功!')location='message.asp'</script>")
response.End()
End if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html charset=gb2312" />
<title>在线留言</title>
<style>
*{margin:0pxpadding:0pxfont-size:14pxcolor:#000000}
a{font-size:14pxcolor:#999999}
body{margin:0 autoline-height:30px}
</style>
</head>
<body>
<table width="930" height="553" border="0" align="center" cellpadding="0" cellspacing="0" >
<tr>
<td width="230" valign="top" align="center">
<br/><br/><br/>
<a href="manage.asp">留言管理</a>
<br/><br/>
</td>
<td width="700" height="553" valign="top" align=left>
留言 <div class=height9> </div>
<br/><br/>
<br/>
<%
message
addmessage
%>
</td>
</tr>
</table>
</body>
</html>
<%
sub addmessage()
%>
<form id="form1" name="form1" method="post" action="?action=addmessagesave">
<table width="519" height="200" border="0">
<tr>
<td width="94" height="55">&nbsp</td>
<td width="415">
<input type="hidden" name="dd" value="0" checked="checked"/> </td>
</tr>
<tr>
<td height="104" align=center>内容:</td>
<td><label>
<textarea name="memo" cols="50" rows="6" ></textarea>
</label></td>
</tr>
<tr>
<td height="33">&nbsp</td>
<td>
<input type="submit" name="Submit" value="提交" /> </td>
</tr>
</table>
</form>
<%
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("<div style=""text-align:center"">没有查到您要查找的留言!</div>")
else
response.write("<div style=width:500pxheight:50pxtext-align:center>暂时没有留言留言!</div>")
End if
else
response.write("<div >")
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
%>
<table width="553" height="100" border="0" cellpadding="0" cellspacing="0" bgcolor=#ffffff style="border:1px solid #ccccccmargin-left:10pxmargin-top:5px">
<tr>
<td style="padding-left:20px">[内容]</td>
<td class="xb-a04"><%=rs("memo")%></td>
<td>&nbsp</td>
</tr>
<tr>
<td height="31" style="padding-left:20px"></td>
<td class="xb-a04"><%
%></td>
<td>[时间:<%=rs("time1")%>]</td>
</tr>
<%if rs("hui")<>"" then%>
<tr>
<td style="padding-left:20px">[回复]</td>
<td colspan="2" class="xb-a04" align="left">&nbsp&nbsp<%=rs("hui")%></td>
</tr>
<%End if%>
</table>
<%
rs.movenext
next
if curpage = 1 then
response.write "</div><BR><div style=width:440pxheight:30pxtext-align:center> 首页 | 上一页 | "
else
response.write "</div><BR><div style=width:440pxheight:30pxtext-align:center ><a href='?pageno=1'>首页</a> | <a href='?pageno="&curpage-1&"&leixing="&leixing&"'>上一页</a> | "
end if
if curpage = rs.pagecount then
response.write "下一页 | 尾页</div>"
else
response.write "<a href='?pageno="&curpage+1&"&leixing="&leixing&"'>下一页</a> | <a href='?pageno="&rs.pagecount&"&leixing="&leixing&"'>尾页</a></div>"
end if
rs.close
end if
End sub
%>
新建一个管理留言的页面,名为manage.asp
同样先改编码为GB2312去掉原来的代码重新输入新的代码如下:
<!--#include file="conn.asp"--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body {font-size: 12px color: #000000 font-family: 宋体}
td {font-size: 12px color: #000000 font-family: 宋体}
.t1 {font:12px 宋体color=000000}
.t2 {font:12px 宋体color:ffffff}
.bt1 {font:14px 宋体color=000000}
.bt2 {font:14px 宋体color:ffffff}
A:link {color: #000066}
A:visited {color: #000066}
A:hover {color: #ff0000}
A.r1:link {font-size:12pxtext-decoration:underlinecolor:#000000}
A.r1:visited {font-size:12pxtext-decoration:underlinecolor:#000000}
A.r1:hover {font-size:12pxtext-decoration:underlinecolor:#ff0000}
A.r2:link {font-size:12pxtext-decoration:underlinecolor:#ffffff}
A.r2:visited {font-size:12pxtext-decoration:underlinecolor:#ffffff}
A.r2:hover {font-size:12pxtext-decoration:underlinecolor:#ff6600}
A.r3:link {font-size:12pxtext-decoration:nonecolor:#000000}
A.r3:visited {font-size:12pxtext-decoration:nonecolor:#000000}
A.r3:hover {font-size:12pxtext-decoration:underlinecolor:#ff0000}
.bd{ background:#03F}
-->
</style>
</head>
<body>
<%
dim filename
dim biaoname
filename="message.asp"
biaoname="message"
%>
<center>
<table width="784" height="45" border="0" align="center">
<tr>
<td width="386" height="41" align=right>留言-管理</td>
<td width="382">&nbsp</td>
</tr>
<tr>
<td width="386" height="41" align=right>&nbsp</td>
<td width="382">&nbsp</td>
</tr>
</table>
<%
if request("action")="" then '显示信息
%>
<TABLE width="393" border="0" cellpadding="4" cellspacing="1" bgcolor="#ffffff" align="center">
<tr height=20 bgcolor="BEBFD9">
<TD width="46" height="20" align="center" class=bd><font color="#FFFFFF"><b>编号</b></font></TD>
<TD width="63" align="center" class=bd><font color="#FFFFFF"><b>留言时间</b></font></TD>
<TD width="98" align="center" class=bd><font color="#FFFFFF"><b>内容</b></font></TD>
<TD width="59" align="center" class=bd><font color="#FFFFFF"><b>回复</b></font></TD>
<TD width="59" align="center" class=bd><font color="#FFFFFF">
<input type='submit' value='删除'>
</font></TD>
</TR>
<%
dim strsql
set rs=server.createobject("adodb.recordset")
strsql="select * from "&biaoname&" order by Id desc"
rs.open strsql,Conn,3,2
if rs.eof then
response.write("<div style=width:500pxheight:500pxtext-align:center>没有信息</div>")
else
'response.write("<div style=width:500pxheight:500px>")
PERPAGE=15
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
%>
<tr height=20 <%if i mod 2 = 0 then
response.write("bgcolor=#cccccc")
else
response.write("bgcolor=#EEEeee")
End if
%>>
<TD height="27" align="center" ><font color="#000000"><b><%=rs("id")%></b></font></TD>
<TD align="center" ><font color="#000000"><b><%=rs("time1")%></b></font></TD>
<TD align="center" ><font color="#000000"><b><%=rs("memo")%></b></font></TD>
<TD align="center" ><a href=?action=hui&id=<%=rs("id")%>>点击回复</a></TD>
<TD align="center" ><a href=?action=del&id=<%=rs("id")%>>删除</a></TD>
</TR>
<%if rs("hui")<>"" then%>
<tr height=20 bgcolor="#eeeeee" >
<TD width="46" height="27" align="center" >回复:</TD>
<TD colspan="4" align="left" >&nbsp
<%=rs("hui")%>
</TD>
</TR>
<%End if%>
<%
rs.movenext
next
%>
</TABLE>
<% if curpage = 1 then
response.write "<br/><div style=width:500pxheight:30pxtext-align:center> 首页 | 上一页 | "
else
response.write "<br/><div style=width:500pxheight:30pxtext-align:center><a href='?pageno=1'>首页</a> | <a href='?pageno="&curpage-1&"&typeid="&request("typeid")&"'>上一页</a> | "
end if
if curpage = rs.pagecount then
response.write "下一页 | 尾页</div>"
else
response.write "<a href='?pageno="&curpage+1&"&leixing="&leixing&"'>下一页</a> | <a href='?pageno="&rs.pagecount&"&typeid="&request("typeid")&"'>尾页</a></div>"
end if
rs.close
end if
end if
'--------------------------------------------------------------修改完成----------------
if request("action")="del" then '删除
id=request("id")
set rs=server.createobject("adodb.recordset")
sql="SELECT * from "&biaoname&" where id="&cstr(id)
rs.open sql,conn,1,3
rs.delete
'rs.update
response.Write "<script>alert('删除成功!')this.location.href='"&filename&"'</SCRIPT>"
end if
if request("action")="hui" then '回复
%>
<form action="?action=huisave" method="post">
<table width="454" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="52" height="168">回复:</td>
<td width="402"><label>
<textarea name="hui" id="textarea" cols="45" rows="5"></textarea>
</label>
<input type="hidden" name="id" value="<%=request("id")%>">
</td>
</tr>
<tr>
<td height="59">&nbsp</td>
<td><label>
<input type="submit" name="button" id="button" value="提交">
</label></td>
</tr>
</table>
</form>
<%End if
if request("action")="huisave" then '删除
if request("hui")="" then
response.write ("<script>window.alert('回复内容不能为空!')this.location.href='message.asp'</script>")
response.end
End if
set rs1=server.CreateObject("ADODB.RecordSet")
sql="SELECT * from "&biaoname&" where id="&request("id")
rs1.open sql,conn,3,2
rs1("hui")=request("hui")
rs1.update
rs1.close
response.write ("<script>window.alert('回复成功!')this.location.href='message.asp'</script>")
End if
%>
</center>
</body>
</html>
运行调式程序
打开一个IE浏览器
输入:http://localhost/
地址
就可以进入到留言板界面,进行留言了
点击左边的留言管理,就可以进入留言管理界面,在留言管理界面可以回复和删除留言信息。
BOF 或 EOF 中有一个是“真”,说明,数据库没找查询到数值,可是你非让他显示,所以出错.
可用 if not rs.eof then (如果记录不为空则执行)
就是留言板很久都打不开
一般是死循环造成的,大部分情况是因为少了个
rs.movenext() (下一条记录)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)