设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 65|回复: 6
打印 上一主题 下一主题

我的留言簿有点问题,请大家帮我解答下

[复制链接]
跳转到指定楼层
1#
发表于 2010-1-7 01:12:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
<!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>
2#
发表于 2010-1-7 01:12:06 | 只看该作者
<!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) [Microsoft][ODBC Microsoft Access Driver] 查询值的数目与目标字段中的数目不同。这是什么错啊?
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>
回复 支持 反对

使用道具 举报

3#
发表于 2010-1-7 01:12:09 | 只看该作者
以下是引用zh286091487在2007-3-24 15:32:30的发言:

<!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) [Microsoft][ODBC Microsoft Access Driver] 查询值的数目与目标字段中的数目不同。这是什么错啊?

错误很明显了,说你的要写入的数据的项目数不一致,换句SQL
sql="insert into lyb(ip,name,url,email,sj,ly)values('"& request.servervariables(remote_addr) &' "," & name & "," & url & "," & email & "," & sj & "," & ly & "')"

看看你以上的数据类型请

注意:如果变量为字符串应写为'"&变量名&"',若为数字应为"&变量名&",

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>
回复 支持 反对

使用道具 举报

4#
发表于 2010-1-7 01:12:12 | 只看该作者
以下是引用zh286091487在2007-3-24 14:52:01的发言:

<!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 (为什么要这一句话)这句话是对你表单的判断,当你的表单元素是"insert"的时候就执行插入操作。


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 如果我的数据库中没东西,这里会出错,应该怎么改?



这里你要做判断就直接写啊!
if rs.eof or rs.bof then
response.write("暂无留言")
else
执行你的循环语句
end if






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>
回复 支持 反对

使用道具 举报

5#
发表于 2010-1-7 01:12:15 | 只看该作者
sql="insert into lyb(ip,name,url,email,sj,ly)values('"
sql=sql & request.servervariables(remote_addr) & "," & name & "," & url & "," & email & "," & sj & "," & ly & "')" (出错地方)
insert into lyb(ip,name,url,email,sj,ly)values('"&request.servervariables(remote_addr) & "," & name & "," & url & "," & email & "," & sj & "," & ly & "')"
问题出在改写双引号的地方没有双引号,而这两个双引号(如果楼主数据库里的类型是文本型)是不够的。
回复 支持 反对

使用道具 举报

6#
发表于 2010-1-7 01:12:18 | 只看该作者
谢谢,解决了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-19 03:30 , Processed in 0.068286 second(s), 8 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表