站内搜索代码问题?
表单代码:<formaction="search.asp"method="get"name="form1"><imgsrc="images_3/kso.gif"width...
表单代码:<form action="search.asp" method="get" name="form1" ><img src="images_3/kso.gif" width="102" height="18" />
<input name="key" type="text" class="form" size="25" />
<input type="radio" name="radiobutton" value="radiobutton1" />学校名称
<input type="radio" name="radiobutton" value="radiobutton2" />参赛选手
<input type="radio" name="radiobutton" value="radiobutton3"/>宝贝名称
<input type="submit" name="submit" value="提交搜索"/>
</form>
search.asp代码
<%
radiobutton=request.form("radiobutton")
key=request.form("key")
%>
<%
select case radiobutton
case "radiobutton1"
sql = "Select * From c Where school like '%"&key&"%' "
case "radiobutton2"
sql = "Select * From c Where player like '%"&key&"%' "
case "radiobutton3"
sql = "Select * From c Where product like '%"&key&"%' "
end select
dim key,conn,rs,sql
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db.mdb")
set rs=server.createobject("adodb.recordset")
rs.open sql,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("school")%></td>
<td><%=rs("player")%></td>
<td><%=rs("product")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>
怎么搜索不到啊?请高手解释?!
access数据库里边,表名c,字段school,player,product。
sql = "Select * From c Where school="东北大学""是能够显示的。 展开
<input name="key" type="text" class="form" size="25" />
<input type="radio" name="radiobutton" value="radiobutton1" />学校名称
<input type="radio" name="radiobutton" value="radiobutton2" />参赛选手
<input type="radio" name="radiobutton" value="radiobutton3"/>宝贝名称
<input type="submit" name="submit" value="提交搜索"/>
</form>
search.asp代码
<%
radiobutton=request.form("radiobutton")
key=request.form("key")
%>
<%
select case radiobutton
case "radiobutton1"
sql = "Select * From c Where school like '%"&key&"%' "
case "radiobutton2"
sql = "Select * From c Where player like '%"&key&"%' "
case "radiobutton3"
sql = "Select * From c Where product like '%"&key&"%' "
end select
dim key,conn,rs,sql
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db.mdb")
set rs=server.createobject("adodb.recordset")
rs.open sql,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("school")%></td>
<td><%=rs("player")%></td>
<td><%=rs("product")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>
怎么搜索不到啊?请高手解释?!
access数据库里边,表名c,字段school,player,product。
sql = "Select * From c Where school="东北大学""是能够显示的。 展开
展开全部
表单代码:
<form action="search.asp" method="post" name="form1" ><img src="images_3/kso.gif" width="102" height="18" />
<input name="key" type="text" class="form" size="25" />
<input type="radio" name="radiobutton" value="radiobutton1" />学校名称
<input type="radio" name="radiobutton" value="radiobutton2" />参赛选手
<input type="radio" name="radiobutton" value="radiobutton3"/>宝贝名称
<input type="submit" name="submit" value="提交搜索"/>
</form>
search.asp代码
<%
dim key,conn,rs,sql
radiobutton=request.form("radiobutton")
key=request.form("key")
if key = "" then
response.write "请输入关键字!"
response.end
end if
select case radiobutton
case "radiobutton1"
sql = "Select * From c Where school like '%"&key&"%'"
case "radiobutton2"
sql = "Select * From c Where player like '%"&key&"%'"
case "radiobutton3"
sql = "Select * From c Where product like '%"&key&"%'"
case else
sql = "Select * From c Where school like '%"&key&"%'"
end select
response.write sql & "<br>"
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db.mdb")
set rs=server.createobject("adodb.recordset")
rs.open sql,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("school")%></td>
<td><%=rs("player")%></td>
<td><%=rs("product")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>
答案已修改
表单提交方式是get ,request.form("key") 取值就有问题
<form action="search.asp" method="post" name="form1" ><img src="images_3/kso.gif" width="102" height="18" />
<input name="key" type="text" class="form" size="25" />
<input type="radio" name="radiobutton" value="radiobutton1" />学校名称
<input type="radio" name="radiobutton" value="radiobutton2" />参赛选手
<input type="radio" name="radiobutton" value="radiobutton3"/>宝贝名称
<input type="submit" name="submit" value="提交搜索"/>
</form>
search.asp代码
<%
dim key,conn,rs,sql
radiobutton=request.form("radiobutton")
key=request.form("key")
if key = "" then
response.write "请输入关键字!"
response.end
end if
select case radiobutton
case "radiobutton1"
sql = "Select * From c Where school like '%"&key&"%'"
case "radiobutton2"
sql = "Select * From c Where player like '%"&key&"%'"
case "radiobutton3"
sql = "Select * From c Where product like '%"&key&"%'"
case else
sql = "Select * From c Where school like '%"&key&"%'"
end select
response.write sql & "<br>"
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("db.mdb")
set rs=server.createobject("adodb.recordset")
rs.open sql,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("school")%></td>
<td><%=rs("player")%></td>
<td><%=rs("product")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
</body>
</html>
答案已修改
表单提交方式是get ,request.form("key") 取值就有问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询