| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 905 人关注过本帖
标题:我的留言簿有点问题,请大家帮我解答下
只看楼主 加入收藏
zh286091487
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-3-22
收藏
 问题点数:0 回复次数:5 
我的留言簿有点问题,请大家帮我解答下

<!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编辑过]

搜索更多相关主题的帖子: 留言簿 解答 
2007-03-24 14:52
gdk2006
Rank: 4
等 级:业余侠客
威 望:8
帖 子:928
专家分:270
注 册:2006-7-2
收藏
得分:0 
以下是引用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>





程序员的悲哀如何找女朋友?
追女解决方案百度“让她着迷”!
2007-03-24 15:12
zh286091487
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-3-22
收藏
得分:0 

<!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>

[此贴子已经被作者于2007-3-24 15:33:44编辑过]

2007-03-24 15:32
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
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 & "')"
问题出在改写双引号的地方没有双引号,而这两个双引号(如果楼主数据库里的类型是文本型)是不够的。
2007-03-24 15:42
gdk2006
Rank: 4
等 级:业余侠客
威 望:8
帖 子:928
专家分:270
注 册:2006-7-2
收藏
得分:0 
以下是引用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>



程序员的悲哀如何找女朋友?
追女解决方案百度“让她着迷”!
2007-03-24 15:44
zh286091487
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2007-3-22
收藏
得分:0 

谢谢,解决了

2007-03-24 17:41
快速回复:我的留言簿有点问题,请大家帮我解答下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038969 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved