请帮忙看看"and"附近有啥错误?

frankrenping 2010-09-09 10:13:07
下面代码有报错:
在关键字 'and' 附近有语法错误。

/asp/matchwith.asp,行 10


<!--#include file="conn/conn.asp"-->
<%
dim Gender1,age1,age2,country,drrTmp
Gender1=request.QueryString("Gender")
age1=request.QueryString("age1")
age2=request.QueryString("age2")
country=request.QueryString("country")
set rs=server.createobject("adodb.recordset")
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "+age1+" and "+age2+") and Country ='"&country&"'"
rs.open sql,conn,2,3
if rs.eof and rs.bof then
response.write("no one match with you want! please try again!")
else
for i=1 to rs.recordcount
if rs.eof then
exit for
end if
drrTmp=drrTmp&rs("Username")&","
session("eeee")=drrTmp
rs.movenext
next
end if
%>
<%
dim hrrTmp
hrrTmp=replace(session("eeee"),",","','")
set rs=server.createobject("adodb.recordset")
sql="select ID,USERNAME,PICPATH from ladlady where USERNAME in ('"&hrrTmp&"')"
rs.open sql,conn,1,3
if rs.eof and rs.bof then
response.Write("no photo!")
else
Do while not rs.eof
str=rs("PICPATH")
rs.movenext
loop
end if
rs.close
set rs = nothing
str=escape(str)
Response.Write str
set conn=nothing
%>

...全文
93 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
数值不能用单引号
Rotel-刘志东 2010-09-09
  • 打赏
  • 举报
回复
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"
frankrenping 2010-09-09
  • 打赏
  • 举报
回复
可以用上面的代码,没报错,谢谢。
Dogfish 2010-09-09
  • 打赏
  • 举报
回复
还以变量不符合要求。
beyond_me21 2010-09-09
  • 打赏
  • 举报
回复
if request.QueryString("age1")="" then
age1=20
else
age1=request.QueryString("age1")
end if
if request.QueryString("age2")="" then
age2=40
else
age2=request.QueryString("age2")
end if
beyond_me21 2010-09-09
  • 打赏
  • 举报
回复
那你在里有age1=request.QueryString("age1")
age2=request.QueryString("age2")
重新给它们赋值了,如果url参数是空值,它们也不会变成默认值的
改成
if age1="" then
age1=20
else
age1=request.QueryString("age1")
end if
if age2="" then
age2=40
else
age2=request.QueryString("age2")
end if
frankrenping 2010-09-09
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 frankrenping 的回复:]
age1,age2 是INT 类型是空值

下面两句是不是要改呢?

age1=request.QueryString("age1")
age2=request.QueryString("age2")
[/Quote]

对不住,把大家搞糊涂了,这里说age1,age2 是空值指的是在这个MATCHWITH.ASP 里显示空值,它们本身在另一页面中有默认值20,40,不知为啥传掉了。
frankrenping 2010-09-09
  • 打赏
  • 举报
回复
age1,age2都有默认值:20,40
不能用条件判断的。
beyond_me21 2010-09-09
  • 打赏
  • 举报
回复
if age1<>"" and age2<>"" then
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "+age1+" and "+age2+") and Country ='"&country&"'"
else
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and Country ='"&country&"'"
end if
frankrenping 2010-09-09
  • 打赏
  • 举报
回复
age1,age2 是INT 类型是空值

下面两句是不是要改呢?

age1=request.QueryString("age1")
age2=request.QueryString("age2")
frankrenping 2010-09-09
  • 打赏
  • 举报
回复
1楼,2楼 都一样的报错
sy_binbin 2010-09-09
  • 打赏
  • 举报
回复
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"' and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"

这样试试
liuwei_IT_love 2010-09-09
  • 打赏
  • 举报
回复
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"
APM60- 2010-09-09
  • 打赏
  • 举报
回复
第1个and前加个空格,“+”换成“&”试试

sql="select Username,Gender,age,Country from customer1 where Gender='" & Gender1 & "' and (age BETWEEN " & age1 & " and " & age2 & ") and Country ='" & country & "'"

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧