三水区财政局:高手看一下这段asp代码,哪里错了?

来源:百度文库 编辑:中科新闻网 时间:2024/03/29 19:46:21
<form name="form1" method="post" action="example6.asp">
搜索:<br>
name =
<input type="text" name="name">
and tel=
<input type="text" name="tel">
<br>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重置">
</form>

example6.asp:
<%
name=request.form("name")
tel=request.form("tel")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
exec="select * from guestbook where name='"+name+"' and tel="+tel
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%
do while not rs.eof
%><tr>
<td><%=rs("name")%></td>
<td><%=rs("tel")%></td>
<td><%=rs("message")%></td>
<td><%=rs("time")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>
exec="select * from guestbook where name='"+name+"' and tel="+tel
看这句

请问'"+name+"'是什么意思呢?

exec="select * from guestbook where name='"+name+"' and tel="+tel
改成
exec="select * from guestbook where name='"&name&"' and tel="&tel

+号是JAVA和C,C++的写法,VB的写法是&

'"+name+"'正确写法应该是'"&name&"'
表示将name的值连接入左边的字符串,
举个例子:
你要查名字为刘,电话为110,SQL语句是这么写的.
"select * from guestbook where name='刘' and tel=110"
当条件不确定时,用变量来代表,此时变量的字符串连接时要加入&号.值为数字时前后不加' , 值不为数字时前后要加'号
也就是这样:
exec="select * from guestbook where name='"&name&"' and tel="&tel

'"+name+"' 就是你数据库中的字段名 有一个叫”name”的字段!
如果出错可能是数据库连接方面的错误吧

exec="select * from guestbook where name='"+name+"' and tel='"+tel+"'"

exec="select * from guestbook where name='"+name+"' and tel='"+tel"'"

如果还不行,看看你的数据库中的表