【www.gdgbn.com--word】
reg.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
%>
检测用户是否存在
<%
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
<script language=javascript教程>
</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=""+msg1+"";
}
else
{
msg="输入正确";
}
}
}
var ch=document.getElementById("password3");
ch.innerHTML=""+msg+"";
}
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=""+msg+"";
}
</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>