黄岛区工商行政局官网:为什么这代码不行?

来源:百度文库 编辑:中科新闻网 时间:2024/05/05 06:07:38
我通过一个表单提交后,即使数据库表中明明存在这样的记录,以下代码返回的结果还是“没有您查询的会员”,无法查询出来,哪儿有错?

<%@language=vbscript codepage=936 %>
<!--#include file="Admin.asp"-->
<!--#include file="Conndb.asp"-->
<!-- #include file="Inc/Head.asp" -->
<%
dim somane
somane=trim(request("somane"))

if somane="" then
response.write "输入不能为空"
response.end
end if

set rs=server.createobject("adodb.recordset")
sql="SELECT * FROM [USER] WHERE somane='%somane%'"
rs.open sql,conn,1,1
%>

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>查询结果</title>
<link rel="stylesheet" href="875q/875q/style.css">
</head>

<body>

<div align="center">
<center>
<table border="1" width="520" cellspacing="0" cellpadding="5" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="100%" colspan="7"> <p align="center">查找结果</p></td>
</tr>
<%
if not rs.eof then
%>
<%do while not rs.eof%>
<tr>
<td width="20%" align="center">用户名</td>
<td width="20%" align="center">姓名</td>
<td width="20%" align="center">密码</td>
<td width="20%" align="center">地址</td>
<td width="20%" align="center">邮编</td>
<td width="20%" align="center">Email</td>
<td width="20%" align="center">电话</td>
</tr>
<tr>
<td width="20%" align="center"><%=rs("username")%></td>
<td width="20%" align="center"><%=rs("somane")%></td>
<td width="20%" align="center"><%=rs("password")%></td>
<td width="20%" align="center"><%=rs("add")%></td>
<td width="20%" align="center"><%=rs("zip")%></td>
<td width="20%" align="center"><%=rs("email")%></td>
<td width="20%" align="center"><%=rs("phone")%></td>
</tr>
<%rs.movenext%>
<%loop%>
<%else%>
<tr>
<td width="100%" colspan="7"><marquee>
没有您所查找的会员</marquee></td>
</tr>
<%end if%>
</table>
</center>
</div>
<%
rs.close
set rs=nothing
%>
</body>

</html>
回2楼,我用您给的代码:sql="SELECT * FROM [USER] WHERE somane like '%somane%'" 还是不行???显示:没有您查询的会员。

sql="SELECT * FROM [USER] WHERE somane='%somane%'"

改为
sql="SELECT * FROM [USER] WHERE somane like '%"&somane&"%'"
或者
sql="SELECT * FROM [USER] WHERE somane ='"&somane&"'"
看你自已的要求是什么了

"SELECT * FROM [USER] WHERE somane like '%"&somane&"%'"

刚刚少加两引号~~用这个试试

把sql="SELECT * FROM [USER] WHERE somane='%somane%'"
改为
sql="SELECT * FROM [USER] WHERE somane="&somane