reg.asp文件
<!--#include file="adoconn.asp"-->
<%
username=request.Form("username")
password=request.Form("password")
sql="select * from puser where y_username='"&username&"'"
rs.open sql,conn,1,1
If Not rs.eof Then
response.write "no"
response.end
End If
rs.close
sql="insert into puser(y_username,y_password) values('"&username&"','"&password&"')"
rs.open sql,conn,1,3
response.write "yes"
%>
adoconn.asp文件代码
<%
set rs=server.CreateObject("adodb.recordset")
db="./username.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
conn.Open connstr
%>
检测用户是否存在
<!--#include file="adoconn.asp"-->
<%
username=Replace(request.querystring("username"),"'","")
sql="select * from puser where y_username='"&username&"'"
rs.open sql,conn,1,1
if rs.eof then
response.write "no"
else
response.write "yes"
end if
rs.close
%>
mdb.数据表
y_id 自动编号
y_username text
y_password text
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> 用户注册 </TITLE>
</HEAD>
<style>
<!--
body,td {font-size:12px;}
input{background-color: #ffffff; color: #000000; font-family: tahoma; font-size: 12px; border: 1px #cccccc double}
-->
</style>
<BODY>
<script language=javascript教程>
<!--
function checkUserName()
{
username=document.getElementById("username").value;
var xmlhttp;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp=new XMLHttpRequest();
}
catch (e)
{
}
}
}
if (username=="")
{
msg="用户名不能为空";
var ch=document.getElementById("check1");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
return false;
}
//创建请求,并使用escape对username编码,以避免乱码
xmlhttp.open("get","checkuser.asp?username="+escape(username)+ "&t=" + new Date().getTime());
xmlhttp.onreadystatechange=function()
{
if(4==xmlhttp.readyState)
{
if(200==xmlhttp.status)
{
if (xmlhttp.responseText=="yes")
{
msg="此用户名已经存在";
}
else
{
msg="输入正确";
}
}
else
{
msg="网络链接失败";
}
var ch=document.getElementById("check1");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
}
xmlhttp.send(null);
return false;
}
//-->
</script>
<script language="javascript">
function checkpass1()
{
var Inform="form1";
var Inputname="password1";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
var Inputname1="password";
eval("Temp1="+Form+Inputname1+".value");
if (Temp!=Temp1)
{
eval(Form+Inputname+".value='';");
eval(Form+Inputname1+".value='';");
eval(Form+Inputname1+".focus();");
msg="两次密码不一样!";
msg1="";
var ch1=document.getElementById("password2");
ch1.innerHTML="<font color='#aaaaaa'>"+msg1+"</font>";
}
else
{
msg="输入正确";
}
}
}
var ch=document.getElementById("password3");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
function checkpass()
{
var Inform="form1";
var Inputname="password";
var Form=Inform+"."
eval("Temp="+Form+Inputname+".value;");
//alert(Temp);
if(Temp==""){
msg="此项不能为空";
}
else
{
if(Temp.length<6||Temp.length>20)
{
msg="密码必须在6~20个字符之间";
}
else
{
msg="输入正确";
}
}
var ch=document.getElementById("password2");
ch.innerHTML="<font color='#aaaaaa'>"+msg+"</font>";
}
</script>
<script language=javascript>
function sendreg()
{
if(this.form1.username.value=="")
{
alert('请输入要注册的用户名');
this.form1.username.focus();
return false;
}
if(this.form1.password.value=="")
{
alert('请输入密码');
this.form1.password.focus();
return false;
}
else
{
if(this.form1.password.value.length<6||this.form1.password.value.length>20)
{
alert('密码长度必须在6~20个字符');
this.form1.password.focus();
return false;
}
}
if(this.form1.password1.value=="")
{
alert('请输入密码');
this.form1.password1.focus();
return false;
}
else
{
if(this.form1.password1.value.length<6||this.form1.password1.value.length>20)
{
alert('密码长度必须在6~20个字符');
this.form1.password1.focus();
return false;
}
}
if(this.form1.password.value!=this.form1.password1.value)
{
this.form1.password.value="";
this.form1.password1.value="";
this.form1.password.focus();
alert('两次密码不一样,请重新输入');
return false;
}
username=this.form1.username.value;
password=this.form1.password.value;
var xmlhttp;
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
try
{
xmlhttp=new XMLHttpRecordset();
}
catch (e)
{
}
}
}
//创建请求,并使用escape对username编码,以避免乱码
xmlhttp.onreadystatechange=function()
{
if(4==xmlhttp.readyState)
{
if(200==xmlhttp.status)
{
if (xmlhttp.responseText=="yes")
{
this.form1.username.value="";
this.form1.password.value="";
this.form1.password1.value="";
document.getElementById("check1").innerHTML="";
document.getElementById("password2").innerHTML="";
document.getElementById("password3").innerHTML="";
alert('注册成功');
}
else
{
this.form1.password.value="";
this.form1.password1.value="";
alert('注册失败');
}
}
else
{
alert('网络连接失败');
}
}
}
//打开连接
xmlhttp.open("post","reg.asp",true)
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
//发送数据
xmlhttp.send("username="+escape(username)+"&password="+escape(password));
}
</script>
<div align="center">
<TABLE border=1 cellpadding=0 cellspacing=0 width=500>
<form name="form1" method="post">
<TR>
<TD colspan=2 align="center" height=25><b>用户注册</b></TD>
</TR>
<TR>
<TD align=right width=100>用户名</TD>
<TD align=left><input type=text size=30 name="username" id="username" onBlur="return checkUserName();"> <span id="check1"></span></TD>
</TR>
<TR>
<TD align=right>密码</TD>
<TD align=left><input type=password size=30 name="password" onBlur="checkpass();" maxlength=20> <span id="password2"></span></TD>
</TR>
<TR>
<TD align=right>确认密码</TD>
<TD align=left><input type=Password size=30 name="password1" onBlur="checkpass1();" maxlength=20> <span id="password3"></span></TD>
</TR>
<TR>
<TD align="center" colspan=2><input type="button" value="注册" onclick="return sendreg();" maxlength=20> <input type="reset" value="重置"></TD>
</TR>
</form>
</TABLE>
</div>
</BODY>
</HTML>