手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

ASP留言板的设计与实现

时间:2024-10-14 01:39:54

1、开始时建立数据库,我们新建一个数据库,进入企业管理器,右击数据库,选择新建数据库

ASP留言板的设计与实现

2、输入一个数据库名称

ASP留言板的设计与实现

3、选中新好的数据库,在右边的窗口中,右击,弹出的菜单里选新建数据表

ASP留言板的设计与实现

4、表名:messageID int 4memo text 16time1 nvarchar 50hui text 16id自动加1memo是留言内容time1留言时间hui回复内容添加,4个字段然后设置ID字段为自动加1,如下图所示

ASP留言板的设计与实现

5、新建一个站点,命名为message新建一个文件夹在D盘,命名为留言板,把IIS的物理路径(参考aspIIS设置的那篇文章http://jingyan.baidu.com/article/fedf0737663b3935ac8977fa.html)设置为D:\留言板把站点的文件路径也设为:D:\留言板

6、在Adobe Dreamweaver CS4 中新建文件

ASP留言板的设计与实现

7、点击创建一个html的文档。

ASP留言板的设计与实现

8、然后修改这个文档的编码,把编码改为GB2312。

ASP留言板的设计与实现
ASP留言板的设计与实现

10、然后在文件中删除默认的那些代码,重新输入以下新代码下面的代码是接sql2000墙绅褡孛数据库<%Di罪焐芡拂m DatabaseDatabase="datamessage"Dim Conn,ConnStrSet conn = Server.CreateObject("ADODB.Connection")ConnStr="Provider=sqloledb;Server=localhost;database="&Database&";uid=sa;pwd="Conn.open ConnStr%>然后保存为conn.asp文件注意选保存文件的类型为所有文件(*.*)

ASP留言板的设计与实现

11、再次新建一个名为:default.asp的文件,这个文件是显示和添加留言的页面编码也需要改为蘅荫酸圉GB2312在这里输入的代码如下:<!--#i荏鱿胫协nclude file="conn.asp"--><%if request("action")="addmessagesave" thenif trim(request("memo"))="" thenResponse.Write("<script lanuage=javascript>alert('留言内容不能为空!');location='message.asp'</script>") response.End()End ifset rsa=Server.CreateObject("ADODB.RecordSet") strsqla="select * from [message]" rsa.open strsqla,conn,3,2 rsa.addnew rsa("memo")=request("memo") rsa("time1")=nowrsa.updateResponse.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:0px;padding:0px;font-size:14px;color:#000000;}a{font-size:14px;color:#999999;}body{margin:0 auto;line-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 subSUB 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:500px;height:50px;text-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 #cccccc;margin-left:10px;margin-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:440px;height:30px;text-align:center> 首页 | 上一页 | " else response.write "</div><BR><div style=width:440px;height:30px;text-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.closeend ifEnd sub%>

12、新建一个管理留言的页面,名为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:12px;text-decoration:underline;color:#000000;}A.r1:visited {font-size:12px;text-decoration:underline;color:#000000;}A.r1:hover {font-size:12px;text-decoration:underline;color:#ff0000;}A.r2:link {font-size:12px;text-decoration:underline;color:#ffffff;}A.r2:visited {font-size:12px;text-decoration:underline;color:#ffffff;}A.r2:hover {font-size:12px;text-decoration:underline;color:#ff6600;}A.r3:link {font-size:12px;text-decoration:none;color:#000000;}A.r3:visited {font-size:12px;text-decoration:none;color:#000000;}A.r3:hover {font-size:12px;text-decoration:underline;color:#ff0000;}.bd{ background:#03F}--></style></head><body><%dim filenamedim 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:500px;height:500px;text-align:center>没有信息</div>") else 'response.write("<div style=width:500px;height: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:500px;height:30px;text-align:center> 首页 | 上一页 | " else response.write "<br/><div style=width:500px;height:30px;text-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 ifif 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 ifif request("action")="huisave" then '删除if request("hui")="" thenresponse.write ("<script>window.alert('回复内容不能为空!');this.location.href='message.asp'</script>") response.endEnd ifset rs1=server.CreateObject("ADODB.RecordSet")sql="SELECT * from "&biaoname&" where id="&request("id")rs1.open sql,conn,3,2rs1("hui")=request("hui")rs1.updaters1.closeresponse.write ("<script>window.alert('回复成功!');this.location.href='message.asp'</script>")End if%></center></body></html>

13、运行调式程序打开一个IE浏览器输入:http://localhost/地址就可以进入到留言板界面,进行留言了点击左边的留言管理,就可以进入留言管理界面,在留言管理界面可以回复和删除留言信息。

© 手抄报圈