asp初学者

hamutailangliuxingyu 2009-08-10 04:22:46

我想做一个登陆页面
页面conn.asp
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mapPath("xignyu.mdb")
%>
页面index.asp
<!--#include file="conn.asp" -->
<HTML>
<HTML>
<HEAD>
<Title>index.asp</Title>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META name="Generator" content="Asp Studio 1.0">
</HEAD>

<BODY>
<table align="center">
<tr>
<td>用户名:</td>
<td>
<input id="name" type="text" >
</td>
</tr>
<tr>
<td>密码:</td>
<td>
<input id="pwd" type="password">
</td>
</tr>
<tr>
<td>
<input type="button" id="tijiao" value="登陆" >
</td>
<td>
<input id="quxiao" type="button" value="注册">
</td>
</tr>
</table>
</BODY>
</HTML>
在index页面中如何判断输入的用户名数据库存在啊??做一个简单的示例给我
...全文
63 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
showoter 2009-08-10
在 Deal.asp处理页面你需要引用conn.asp的数据库连接文件。你在Deal.asp文件前面加
<!--#include file="conn.asp"-->
然后把sql="select * form [tablename]..."中的tablename改为你的数据库表名,再试试。
回复
[Quote=引用 2 楼 hookee 的回复:]
index.asp
HTML code<HTML><HTML><HEAD><Title>index.asp</Title><METAhttp-equiv="Content-Type" content="text/html; charset=gb2312"><METAname="Generator" content="Asp Studio 1.0"></HEAD><BODY><formaction="login.asp" method="post"><tablealign="center"><tr><td>用户名:</td><td><inputid="name" type="text" onblur="hf.location.href='check.asp?name='+escape(this.value);"><spanid="pad"></span></td></tr><tr><td>密码:</td><td><inputid="pwd" type="password"></td></tr><tr><td><inputtype="submit" id="tijiao" value="登陆"></td><td><inputid="quxiao" type="button" value="注册"></td></tr></table></form><iframename="hf"></iframe></BODY></HTML>

check.asp
HTML code<!--#include file="conn.asp"--><%
s=""
username=Trim(Request("name"))
username=Replace(username,"'","''")
sql="SELECT COUNT(*) FROM [users] WHERE [username]='"& username&"'Set rs=CreateObject("ADODB.RecordSet")
rs.cursorLocation=3
rs.open sql,conn,1,1If rs(0)=0Then
s="不存在"Else
s="存在"EndIf
rs.closeset rs=nothing
conn.closeset conn=nothing%><script>
window.onload=function(){
parent.document.getElementById("pad").innerHTML="<%=s%>";
location.replace("about:blank");
}</script>
[/Quote]
怎么不管存在还是不存在怎么都能进去的啊
回复
[Quote=引用 3 楼 showoter 的回复:]
'前台form提交如下

<BODY>
<form name="form1" action="Deal.asp" method="post" >
<table align="center">
<tr>
<td>用户名: </td>
<td>
<input id="name" type="text" >
</td>
</tr>
<tr>
<td>密码: </td>
<td>
<input id="pwd" type="password">
</td>
</tr>
<tr>
<td>
<input type="button"  id="tijiao"  value="登陆" >
</td>
<td>
<input id="quxiao" type="button" value="注册">
</td>
</tr>
</table>
</form>
</BODY>

'Deal.asp处理
<%
name = trim(Request("name")
psd = trim(Request("psd"))
set rs = server.createobject("Adodb.Recordset")
sql = "select * from [tablename] where name=" & name
rs.open sql,conn,1,1
if rs.recordcount>0 then
  if rs("psd")=psd then
  response.write(" <script>alert('登陆成功!');location.href('跳转页面地址'); </script>")
  response.end()
  else
  response.write(" <script>alert('密码错误!');histroy.go(-1); </script>")
  response.end()
  end if
else
  response.write(" <script>alert('用户名错误!');history.go(-1); </script>")
  response.end()
end if
%>
[/Quote]
回复
回复
showoter 2009-08-10
'前台form提交如下

<BODY>
<form name="form1" action="Deal.asp" method="post" >
<table align="center">
<tr>
<td>用户名: </td>
<td>
<input id="name" type="text" >
</td>
</tr>
<tr>
<td>密码: </td>
<td>
<input id="pwd" type="password">
</td>
</tr>
<tr>
<td>
<input type="button" id="tijiao" value="登陆" >
</td>
<td>
<input id="quxiao" type="button" value="注册">
</td>
</tr>
</table>
</form>
</BODY>

'Deal.asp处理
<%
name = trim(Request("name")
psd = trim(Request("psd"))
set rs = server.createobject("Adodb.Recordset")
sql = "select * from [tablename] where name=" & name
rs.open sql,conn,1,1
if rs.recordcount>0 then
if rs("psd")=psd then
response.write("<script>alert('登陆成功!');location.href('跳转页面地址');</script>")
response.end()
else
response.write("<script>alert('密码错误!');histroy.go(-1);</script>")
response.end()
end if
else
response.write("<script>alert('用户名错误!');history.go(-1);</script>")
response.end()
end if
%>
回复
hookee 2009-08-10
index.asp

<HTML>
<HTML>
<HEAD>
<Title>index.asp </Title>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<META name="Generator" content="Asp Studio 1.0">
</HEAD>

<BODY>
<form action="login.asp" method="post">
<table align="center">
<tr>
<td>用户名: </td>
<td>
<input id="name" type="text" onblur="hf.location.href='check.asp?name='+escape(this.value);"> <span id="pad"></span>
</td>
</tr>
<tr>
<td>密码: </td>
<td>
<input id="pwd" type="password">
</td>
</tr>
<tr>
<td>
<input type="submit" id="tijiao" value="登陆" >
</td>
<td>
<input id="quxiao" type="button" value="注册">
</td>
</tr>
</table>
</form>

<iframe name="hf"></iframe>

</BODY>
</HTML>


check.asp

<!--#include file="conn.asp" -->
<%
s = ""
username = Trim(Request("name"))
username = Replace(username, "'", "''")
sql = "SELECT COUNT(*) FROM [users] WHERE [username]='" & username & "'
Set rs = CreateObject("ADODB.RecordSet")
rs.cursorLocation = 3
rs.open sql,conn,1,1
If rs(0)= 0 Then
s = "不存在"
Else
s = "存在"
End If
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
<script>
window.onload=function(){
parent.document.getElementById("pad").innerHTML = "<%=s%>";
location.replace("about:blank");
}
</script>
回复
name = Request.Form("name")
Set Rs = conn.Execute("Select 1 From [tablename] where name='"&name &"' ")
If Not Rs.Eof Then
Response.write "不存在"
Else
Response.write "存在"
End If
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告