求大神纠错啊!!在线等。。
本人最近在维护一个asp的网站,奈何不怎么熟悉,求大神指导。下面的代码,打开网页报500错误,我知道是sql语句拼接的问题,可我找度娘问了好几次,都弄不对。无奈中,只能求助各位大神了。。
求错误原因和修改办法,虽然我不是搞asp的,但多会点知识也不压身啊。在线等,有点急。。。有结果马上结贴!
<%
user_name=""
user_job_number=""
user_id_number=""
If IsEmpty(request.Form("user_name")) Then
user_name="or name like '%" & request.Form("user_name") & "%'"
End If
If IsEmpty(request.Form("user_job_number")) Then
user_job_number="or job_number like '%" & request.Form("user_job_number") & "%'"
End If
If IsEmpty(request.Form("user_id_number")) Then
user_id_number="or id_number like '%" & request.Form("user_id_number") & "%'"
End If
set rs=server.CreateObject("adodb.recordset")
sql="select * from people where 1=1" & user_name & user_job_number & user_id_number
rs.open sql,conn,1,1
if rs.eof then
response.Redirect("index.asp")
response.end()
end if
rs.close
set rs=nothing
%>
------解决方案--------------------If not IsEmpty(request.Form("user_name")) Then
user_name=" or name like '%" & request.Form("user_name") & "%'"
End If
If not IsEmpty(request.Form("user_job_number")) Then
user_job_number=" or job_number like '%" & request.Form("user_job_number") & "%'"
End If
If not IsEmpty(request.Form("user_id_number")) Then
user_id_number=" or id_number like '%" & request.Form("user_id_number") & "%'"
End If
换这个看看
------解决方案--------------------name=Request.QueryString("name") '姓名
sex=Request.QueryString("sex") '性别
call=Request.QueryString("call") '电话
Sql= "Select * from 表名 where 1=1" '1=1 避免所有查询字段为空时出错
if name <>"" then
Sql= Sql & "and 姓名 like '%"& name &"%'"
end if
if sex <>"" then
Sql= Sql & "and 性别 = '"& sex &"'" '这个不是模糊查询了
end if
if call <>"" then
Sql= Sql & "and 电话 like '%"& call &"%'"
end if