新微赢技术网

标题: 我的留言簿有点问题,请大家帮我解答下 [打印本页]

作者: 封xin封mg    时间: 2010-1-7 01:12
标题: 我的留言簿有点问题,请大家帮我解答下
<!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>
作者: 没心没肺    时间: 2010-1-7 01:12
<!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>
作者: .嵿峜繌嗲﹖    时间: 2010-1-7 01:12
以下是引用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>
作者: 新时代    时间: 2010-1-7 01: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>
作者: 玩QQ名字千万    时间: 2010-1-7 01:12
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 & "')"
问题出在改写双引号的地方没有双引号,而这两个双引号(如果楼主数据库里的类型是文本型)是不够的。
作者: 兮哩糊涂の斗    时间: 2010-1-7 01:12
谢谢,解决了




欢迎光临 新微赢技术网 (http://bbs.weiying.cn/) Powered by Discuz! X3.2