做了几年的网页,到处留言千千万,用过各种留言本万万千。可惜令我喜欢的留言本真少(55555),慢慢的速度让我无法忍受,丑陋的界面让我心烦,图标更是让人作呕,所以我下决心写一个自己的超级留言本,阿余半夜起来,挑灯奋战,忙了一整天,终于。咱的“超级留言本1.0”出现了,它速度极快。因为根本就是html的,并没有一个冗余的代码,图标全是根据俺自己 and 俺的“那个”绘制的,还可以随时修改配色方案,呵呵,不敢独享,赶忙写给大家,不对的地方,不要忘了到 www.zydn.net 去骂呀,阿余在那里等候你的批判。
好了,下里具体讲讲我的留言本怎么做的吧。(第一次写教程,还不懂怎么开头)
为了方便管理,这是一个基于数据库的留言本程序,先看看我的库结构,(access 2000)
库中有三个表,第一个 ly 就是用来放留言的啦,有12个字段。。。。(现在看来,用不了这么多的,我也不想改啦)
1姓名 2性别 3地址 4内容(备注) 5时间(日期时间) 6日期(日期时间) 7心情 8id(自动编号) 9url 10 urlname 11 email 12 脸,
第二个表 color 用于存放配色方案 有3个字段 1 名称 2 id(自动编号) 3 方案
第三一个表 pas 用来放管理员密码啦,但这个程序的安全性没有充分考虑的,朋友们要自已修改啦。
首先做一个表单,用于录入我们的留言,存为文件名: index1.htm 代码如下,你把他全复制了在fontpage中粘出来就得啦。
****************************
<html>
<head>
<title>卓越留言本-填写留言</title></head>
<body bgcolor="#deeefe">
<div><center>
<table border="0" width="95%" height="270" bgcolor="#fcffe6" style="border: 1 solid #000080">
<tr> <td width="100%" height="16"> <p align="center"><font size="5" color="#0000ff"><b>阿余的超级留言本</b></font></td>
</tr><tr><td width="100%" height="187">
<form method="post" action="savely.asp">
<p align="left"> 尊姓大名:<input type="text" name="xm" size="33">**
性别:<select size="1" name="xb">
<option selected>男</option>
<option>女</option>
</select></p>
<p align="left"> 来自:<input type="text" name="lz" size="38">
email:<input type="text" name="ema" size="37"></p>
<p align="left"> 网站名:<input type="text" name="urname" size="35">
网址:<input type="text" name="urla" size="37"></p>
<p align="left"> 现在的心情:<input type="radio" value="大笑" checked name="xq">大笑
<input type="radio" name="xq" value="愉快">愉快 <input type="radio" name="xq" value="平静">平静
<input type="radio" name="xq" value="忧郁">忧郁 <input type="radio" name="xq" value="痛苦">痛苦
<input type="radio" name="xq" value="发怒">发怒</p>
<p align="left"> 留言内容:<font size="2">(不能超过200汉字)**</font></p>
<p align="center"><textarea rows="5" name="lr" cols="87"></textarea></p>
<p align="center"><input type="submit" value="写好啦" name="b1"><input type="reset" value="重新写" name="b2"></p>
</form> <p align="center"><a href="disp.asp">返回</a></td>
</tr> <tr> <td width="100%" height="27"> </td> </tr><tr> <td width="100%" height="16"> </td> </tr> </table> </center></div> </body> </html>
*************************
然后再写一个程序把我们这些内容加入到数据库中,我就不全写出来啦,这样的话,这篇文章会好长的,你们只要到 www.zydn.net 去下一人来就得了,文件名是savely.asp
注意其中这几个语句:
abcc=len(lr)
sclr=""
absn=1
do while absn<abcc
alsa1=mid(lr,absn,1)
if asc(alsa1)=13 then alsa1="<br>"
if alsa1="<" then alsa1="<"
if alsa1=">" then alsa1=">"
sclr=sclr+alsa1
absn=absn+1
loop
lr=sclr
这是用来判断用户输入的内容中是否有超文本代码,是否有回车,并把超 文件的“<”“>”转为“<”“>”,把回车(换行)转为“<br>”,稍加发挥,这段程序可以做不少事,如哪位朋友有更好的办法不妨告诉我一声。存完内容后用response.redirect "disp.asp" 把库中的内容显示出来。
好啦,然后把数据库显出来不就成了一个留言本? 开始的时候我也这样想,但我发现这要读数据库,asp文件要经asp.dll,速度很慢这哪还能叫超级留言本!!阿余苦苦思索了整整。。。。不知多久。。(想着想着睡着啦),一觉醒来,茅塞顿开,把数据库中的东东读出来,再用filesystemobject写为html不就行了?读html可比读数据库快多啦,啊。说干就干,于是disp.asp 这个文件出来啦
********************************以下是disp.asp的全部内容
<!–#include file="color.inc"–>
<%
set conn=server.createobject("adodb.connection")
connstr="dbq="+server.mappath("zyly.mdb")+";defaultdir=;driver={microsoft access driver (*.mdb)};"
conn.open connstr
sql="select * from ly order by id"
dim ra
set ra=server.createobject("adodb.recordset")
ra.open sql,conn,1,1 *****以上用于连接数据库,读出库中的内容,典型的ado连接access的数据库
if ra.eof or ra.bof then
%>尚无内容<%
else
set xm=ra("姓名")
set xb=ra("性别")
set lz=ra("地址")
set lr=ra("内容")
set dat=ra("日期")
set tim=ra("时间")
set emai=ra("email")
set ur=ra("url")
set urlname=ra("urlname")
set lian=ra("脸")
set biao=ra("心情")
i=1
ra.movelast
lylr=""
do while not ra.bof and i<=100 由于有这一句 i<=100所以,本留言最多显示100条留言,要显示更多的话,把这个数改大一些就行啦
lylr=lylr+" <table style=font-size: 9pt; color: "+co5+"; border: 1 solid "+co3+" border=0 width=91% bgcolor="+co2+"><tr><td width=19% rowspan=3 > <img border=0 src="+lian+" alt="+biao+" width=33 ></td><td width=41%>姓名: "+xm+"</td> <td width=40% >时间:"+cstr(year(dat))+"年"+cstr(month(dat))+"月"+cstr(day(dat))+"日 "+tim+"</td></tr><tr>" %>
<% if trim(emai)<>"" then
lylr=lylr+"<td width=41%>email: <a href=mailto:"+emai+">"+emai+"</a></td>"
end if
if trim(urlname)<>"" or trim(ur)<>"" then
lylr=lylr+"<td width=40% >主页:<a href="+ur+">"+urlname+"</a></td>"
end if
lylr=lylr+"</tr><tr>"
if trim(lz)<>"" then
lylr=lylr+"<td width=81% colspan=2>来自: "+lz+"</td>"
end if
lylr=lylr+"</tr><tr><td width=100% colspan=3>"+lr+"</td></tr></table><table style=font-size: 5pt><tr><td ></td></tr></table>"
i=i+1
ra.moveprevious
loop 以上把数据库中的内容全读到了lylr变量中,一篇留言就做好啦,这时如用<%=lylr%>显示出来就是一篇不错的留言了,注意其中不少用颜色地方都换成变量了,这是为了好改页面的颜色,
ra.close
end if %>
<%lylr1="<html><head><meta http-equiv=content-language content=zh-cn><meta http-equiv=content-type content=text/html; charset=gb2312><title>卓越电脑留言本</title></head><body bgcolor="+co1+"><div align=center> <center><table width=91% cellspacing cellpadding ><tr><td width=100%><p align=center><b><font color="+co4+">"+bt+"</font></b></td></tr></table><table width=91% cellspacing cellpadding style=font-size: 9pt bgcolor=#ffffd9> <tr><td colspan=3></td></tr><tr><td align=center><a href=index1.htm>写点什么</a></td><td align=center><a href=gl.htm>管理版面</a></td> <td align=center><a href=../>退出</a></td> </tr></table>"%>
<!–#include file="path.inc"–>
<%
lylr=lylr1+"<br>"+lylr+"<hr width=94% color="+co4+" size=1><table border=0 width=91% style=font-size: 9pt; border-style: solid; border-width: 1 bgcolor=#adbf9f><tr><td width=33%>此程序由重庆市<a href=http://www.zydn.net>卓越电脑公司</a>开发</td> <td width=33% >email: <a href=mailto:coolkk@21cn.com>coolkk@21cn.com</a></td><td width=34%>电话:023-48650340 023-48658712</td></tr><tr><td width=33%>地址:重庆市綦江县中山路卓越电脑公司</td> <td> 卓越留言本2.0版 </td><td width=34% >邮编:401420</td></tr></table> </center></div></body></html>"
好啦,到这里我们的留言内容全部做好啦。
set fs= createobject("scripting.filesystemobject")
set ts=fs.createtextfile(""&patha&"index.htm",true) patha是放在path.inc中的一个变量,当前路径
ts.writeline(lylr) 建立一个文件,并把留言内容(lylr)写入其中,
ts.close
response.redirect "index.htm" 转向我们建立的 index.htm 留言显示出来啦
%>
***************** 以上是disp.asp的全部内容
开始的 <!–#include file="color.inc"–> 用于调入留言本的配色方案,而后的<!–#include file="path.inc"–>用于调入当前路径。
下面对color.inc 和 path.inc 作个说明
color.inc 由以后要介绍的一个配色方案程序生成,
而path.inc的内容如下:
<%
patha=server.mappath("path.asp")
patha=left(patha,len(patha)-8) %>用于取得程序存放的路径,由于要在别的地方用所以就写成一个单独的文件了。这个方法好象很笨,望高手能教教阿余。
好啦,今天就写到这里,明天继续,您可到www.zydn.net 下载全部源程序。
如果谁有意见的话请给我来信coolkk@21cn.com 或访问我的网站www.zydn.net
