SQL搜索表单报错ASP

来源:百度知道 编辑:UC知道 时间:2024/05/26 06:55:09
<%
t1=request.form("tiaojian1")
t1=Replace(t1,","," or") '逗号替换成OR
t2=request.form("tiaojian2")
't2=Replace(t2,",",".") '逗号替换成OR
t3=request.form("tiaojian3")
t3=Replace(t3,","," and")

if t1="" and t2="" and t3="" then
response.Write"请选择搜索条件在提交"
response.End
else
if t1="" and t2<>"" and t3<>"" then
exec="select * from zhuku where ("&t2&") and "&t3&" order by usernames asc"
else
if t1<>"" and t2="" and t3<>"" then
exec="select * from zhuku where ("&t1&") and "&t3&" order by taocan asc"
else
if t1<>"" and t2<>"" and t3="" then
exec="select * from zhuku where (&quo

你的代码的If结构太复杂了,很容易出错,if t1="" and t2<>"" and t3="" then
exec="select * from zhuku where "&t2&" order by taocan asc"
的后面少了一个 else

if t1="" and t2<>"" and t3=""
的情况下
if t1<>"" and t2="" and t3="" 和
if t1<>"" and t2<>"" and t3<>""
绝对不可能成立,所以
exec="select * from zhuku where "&t1&" order by id asc" 和
exec="select * from zhuku where ("&t1&") and "&t2&" and "&t3&" order by id asc"
这两个语句永远不会被执行

其实可以简单地写成这样:

<%
t1=request.form("tiaojian1")
t1=Replace(t1,","," or") '逗号替换成OR
t2=request.form("tiaojian2")
't2=Replace(t2,",",".") '逗号替换成OR
t3=request.form("tiaojian3"