<!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>
</head>
<body>
<%
mydsn="dsn=information"
set conn=server.createobject("adodb.connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=D:\网站学习\database\information.mdb"
conn.Open Strconn
if request.form("task")="insert" then (为什么要这一句话)
if request.form("name")="" then
name="匿名"
else
name=request.form("name")
end if
if request.form("email")="" then
email="无"
else
email=request.form("email")
end if
if request.form("url")="" then
url="无"
else
url=request.form("url")
end if
sj=date()
sj=sj & " " & hour(time()) & ":" & minute(time())
if request("ly")="" then
response.write("请输入留言!!")
response.end
else
ly=request.form("ly")
end if
sql="insert into lyb(ip,name,url,email,sj,ly)values('"
sql=sql & request.servervariables(remote_addr) & "," & name & "," & url & "," & email & "," & sj & "," & ly & "')" (出错地方)
conn.execute(sql)
end if
set rs=server.createobject("adodb.recordset")
rs.open "select * from guestbook order by sj desc",mydsn,3,1
rs.pagesize=3
rs.absolutepage=1
if request("page")<>"" then rs.absolutepage=request("page")
rowcount=rs.pagesize
%>
<br />
<form method="post" action="<%=request.servervariables("script_name")%>"><br />
<input type="hidden" name="task" value="insert" /><br /> (有什么用啊)
姓名:<input type="text" size="20" name="name" /><br />
email:<input type="text" size="20" name="email" /><br />
主页:<input type="text" size="20" name="url" /><br />
留言:<br />
<textarea rows="5" cols="60" name="ly">
</textarea><br />
<input type="submit" value="记入留言簿" name="b1" />
<input type="reset" value="重写" name="b2" />
</form>
<hr />
<%
if not rs.eof then 如果我的数据库中没东西,这里会出错,应该怎么改?
do while not rs.eof and rowcount>0
%>
日期:<%=rs("sj")%><br />
姓名:<%=rs("name")%><br />
主页:<%=rs("url")%><br />
email:<%=rs("email")%><br />
留言:<br />
<%=rs("ly")%><br />
<hr />
<%
rowcount=rowcount-1
rs.movenext
loop
else
response.write("无")
end if
%>
<br />
<%
if rs.pagecount>1 then
%>
<table border="0">
<tr>
<td>留言分页</td>
<%
for i=1 to rs.pagecount
%>
<td>
<a href="<%=request.servervariables("script_name")%>?page=<%=i%>"><%=i%></a>
</td>
<%next%>
</tr>
</table>
<%
end if
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
</body>
</html>
[此贴子已经被作者于2007-3-24 15:05:43编辑过]