<?php
//创建一个XML格式输出
header('Content-Type: text/xml');
//创建XML头
echo '<?xml version="1.0" encoding="gb2312" standalone="yes" ?>';
//创建<response>元素
echo '<response>';
$stu_id=$_GET[online_regname];
$stu_name=$_GET[online_sturealname];
$stu_pwd=$_GET[online_regpwd1];
$stu_sex=$_GET[online_stusex];
$stu_question=$_GET[online_stuquestion];
$stu_answer=$_GET[online_stuanswer];
$stu_faculty=$_GET[online_stufaculty];
$stu_subject=$_GET[online_stusubject];
$stu_class=$_GET[online_stuclass];
$stu_enteryear=$_GET[online_stuenteryear];
$stu_email=$_GET[online_email];
$stu_contact=$_GET[online_stutelephone];
//根据从客户端获取的用户创建输出
include("conn/conn.php");
$query=mysql_query("insert into tb_student(id,name,pwd,sex,question,answer,faculty,subject,class,enteryear,email,contact) values('$stu_id','$stu_name','$stu_pwd','$stu_sex','$stu_question','$stu_answer','$stu_faculty','$stu_subject','$stu_class','$stu_enteryear','$stu_email','$stu_contact')");
if($query == TRUE){
echo "<script>alert('注册成功!');window.location.href='login.php';</script>";
}
//关闭<response>元素
echo '</response>';
?>
//创建一个XML格式输出
header('Content-Type: text/xml');
//创建XML头
echo '<?xml version="1.0" encoding="gb2312" standalone="yes" ?>';
//创建<response>元素
echo '<response>';
$stu_id=$_GET[online_regname];
$stu_name=$_GET[online_sturealname];
$stu_pwd=$_GET[online_regpwd1];
$stu_sex=$_GET[online_stusex];
$stu_question=$_GET[online_stuquestion];
$stu_answer=$_GET[online_stuanswer];
$stu_faculty=$_GET[online_stufaculty];
$stu_subject=$_GET[online_stusubject];
$stu_class=$_GET[online_stuclass];
$stu_enteryear=$_GET[online_stuenteryear];
$stu_email=$_GET[online_email];
$stu_contact=$_GET[online_stutelephone];
//根据从客户端获取的用户创建输出
include("conn/conn.php");
$query=mysql_query("insert into tb_student(id,name,pwd,sex,question,answer,faculty,subject,class,enteryear,email,contact) values('$stu_id','$stu_name','$stu_pwd','$stu_sex','$stu_question','$stu_answer','$stu_faculty','$stu_subject','$stu_class','$stu_enteryear','$stu_email','$stu_contact')");
if($query == TRUE){
echo "<script>alert('注册成功!');window.location.href='login.php';</script>";
}
//关闭<response>元素
echo '</response>';
?>
function $(id){
return document.getElementById(id);
}
window.onload = function(){
$('regname').focus();
var cname1,cname2,cpwd1,cpwd2,cemail,csex,cquestion,canswer,cfaculty,csubject,cclass,ctelephone,centeryear;
//设置激活按钮
function chkreg(){
if((cname1 == 'yes') && (cname2 == 'yes') && (cpwd1 == 'yes') && (cpwd2 == 'yes') && (cemail == 'yes') && (csex == 'yes') && (cquestion == 'yes') && (canswer == 'yes') && (cfaculty == 'yes') && (csubject == 'yes') && (cclass == 'yes') && (ctelephone == 'yes') && (centeryear == 'yes')){
$('regbtn').disabled = false;
}else{
$('regbtn').disabled = true;
}
}
//验证用户名
$('regname').onkeyup = function (){
name = $('regname').value;
cname2 = '';
if(name.match(/^[a-zA-Z_]*/) != ''){
$('namediv').innerHTML = '<font color=red>必须以数字构成</font>';
cname1 = '';
}else if((name.length > 10)|(name.length < 10)){
$('namediv').innerHTML = '<font color=red>注册名称必须等于10位</font>';
cname1 = '';
}else{
$('namediv').innerHTML = '<font color=green>注册名称符合标准</font>';
cname1 = 'yes';
}
chkreg();
}
//验证是否存在该用户
$('regname').onblur = function(){
name = $('regname').value;
if(cname1 == 'yes'){
xmlhttp.open('get','chkname.php?name='+name,true);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
var msg = xmlhttp.responseText;
if(msg == '1'){
$('namediv').innerHTML="<font color=green>恭喜您,该用户名可以使用!</font>";
cname2 = 'yes';
}else if(msg == '2'){
$('namediv').innerHTML="<font color=red>用户名被占用!</font>";
cname2 = '';
}else{
$('namediv').innerHTML="<font color=red>"+msg+"</font>";
cname2 = '';
}
}
}
chkreg();
}
xmlhttp.send(null);
}
}
//真实姓名
$('sturealname').onkeyup = function (){
if(sturealname.value == ""){
$('realnamediv').innerHTML = '<font color=red>不能为空</font>';
cname2 = '';
}else{
$('realnamediv').innerHTML = '<font color=green>符合标准</font>';
cname2 = 'yes';
}
chkreg();
}
//验证密码
$('regpwd1').onkeyup = function(){
pwd = $('regpwd1').value;
pwd2 = $('regpwd2').value;
if(pwd.length < 6){
$('pwddiv1').innerHTML = '<font color=red>密码长度最少需要6位</font>';
cpwd1 = '';
}else if(pwd.length >= 6 && pwd.length < 12){
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:弱</font>';
cpwd1 = 'yes';
}else if((pwd.match(/^[0-9]*$/)!=null) || (pwd.match(/^[a-zA-Z]*$/) != null )){
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:中</font>';
cpwd1 = 'yes';
}else{
$('pwddiv1').innerHTML = '<font color=green>密码符合要求。密码强度:高</font>';
cpwd1 = 'yes';
}
if(pwd2 != '' && pwd != pwd2){
$('pwddiv2').innerHTML = '<font color=red>两次密码不一致!</font>';
cpwd2 = '';
}else if(pwd2 != '' && pwd == pwd2){
$('pwddiv2').innerHTML = '<font color=green>密码输入正确</font>';
cpwd2 = 'yes';
}
chkreg();
}
//验证确认密码
$('regpwd2').onkeyup = function(){
pwd1 = $('regpwd1').value;
pwd2 = $('regpwd2').value;
if(pwd1 != pwd2){
$('pwddiv2').innerHTML = '<font color=red>两次密码不一致!</font>';
cpwd2 = '';
}else{
$('pwddiv2').innerHTML = '<font color=green>密码输入正确</font>';
cpwd2 = 'yes';
chkreg();
}
}
//验证email
$('email').onkeyup = function(){
emailreg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
$('email').value.match(emailreg);
if($('email').value.match(emailreg) == null){
$('emaildiv').innerHTML = '<font color=red>错误的email格式</font>';
cemail = '';
}else{
$('emaildiv').innerHTML = '<font color=green>输入正确</font>';
cemail = 'yes';
}
chkreg();
}
//验证性别
$('stusex').onkeyup = function (){
sexreg = /男|女/;
$('stusex').value.match(sexreg);
if($('stusex').value.match(sexreg) == null){
$('sexdiv').innerHTML = '<font color=red>错误</font>';
csex = '';
}else{
$('sexdiv').innerHTML = '<font color=green>符合标准</font>';
csex = 'yes';
}
chkreg();
}
//密码问题
$('stuquestion').onkeyup = function (){
if(stuquestion.value == ""){
$('questiondiv').innerHTML = '<font color=red>不能为空</font>';
cquestion = '';
}else{
$('questiondiv').innerHTML = '<font color=green>符合标准</font>';
cquestion = 'yes';
}
chkreg();
}
//密码答案
$('stuanswer').onkeyup = function (){
if(stuanswer.value == ""){
$('answerdiv').innerHTML = '<font color=red>不能为空</font>';
canswer = '';
}else{
$('answerdiv').innerHTML = '<font color=green>符合标准</font>';
canswer = 'yes';
}
chkreg();
}
//学生院系
$('stufaculty').onkeyup = function (){
if(stufaculty.value == ""){
$('facultydiv').innerHTML = '<font color=red>不能为空</font>';
cfaculty = '';
}else{
$('facultydiv').innerHTML = '<font color=green>符合标准</font>';
cfaculty = 'yes';
}
chkreg();
}
//学生专业
$('stusubject').onkeyup = function (){
if(stusubject.value == ""){
$('subjectdiv').innerHTML = '<font color=red>不能为空</font>';
csubject = '';
}else{
$('subjectdiv').innerHTML = '<font color=green>符合标准</font>';
csubject = 'yes';
}
chkreg();
}
//学生班级
$('stuclass').onkeyup = function (){
if(stuclass.value == ""){
$('classdiv').innerHTML = '<font color=red>不能为空</font>';
cclass = '';
}else{
$('classdiv').innerHTML = '<font color=green>符合标准</font>';
cclass = 'yes';
}
chkreg();
}
//验证联系方式
$('stutelephone').onkeyup = function (){
telephonereg = /\d{11}/;
$('stutelephone').value.match(telephonereg);
if($('stutelephone').value.match(telephonereg) == null){
$('telephonediv').innerHTML = '<font color=red>以11位数字构成</font>';
ctelephone = '';
}else{
$('telephonediv').innerHTML = '<font color=green>手机号码符合标准</font>';
ctelephone = 'yes';
}
chkreg();
}
//验证入学年份
$('stuenteryear').onkeyup = function (){
enteryearreg = /\d{4}/;
$('stuenteryear').value.match(enteryearreg);
if($('stuenteryear').value.match(enteryearreg) == null){
$('enteryeardiv').innerHTML = '<font color=red>以4位数字构成,如YYYY</font>';
centeryear = '';
}else{
$('enteryeardiv').innerHTML = '<font color=green>符合标准</font>';
centeryear = 'yes';
}
chkreg();
}
//登录按钮
$('logbtn').onclick = function(){
window.open('login.php','_parent','',false);
}
}
//定义XMLHttpRrequest对象
var xmlHttp=createXmlHttpRequestObject();//获取XMLHttpRrequest对象
function createXmlHttpRequestObject(){
//用来存储将要使用的XMLHttpRrequest对象
var xmlHttp;
//如果在internet Explorer下运行
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
xmlHttp=false;
} }else{
//如果在Mozilla或其他的浏览器下运行
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
xmlHttp=false;
}
}
//返回创建的对象或显示错误信息
if(!xmlHttp)
alert("返回创建的对象或显示错误信息");
else
return xmlHttp;
}
//使用XMLHttpRequest对象创建异步HTTP请求
function process(){
//在xmlHttp对象不忙时进行处理
if(xmlHttp.readyState==4 || xmlHttp.readyState==0){
//获取用户在线表单中输入的姓名
regnames = document.getElementById("regname").value;
sturealnames = document.getElementById("sturealname").value;
regpwd1s =document.getElementById("regpwd1").value;
stusexs =document.getElementById("stusex").value;
stuquestions =document.getElementById("stuquestion").value;
stuanswers =document.getElementById("stuanswer").value;
stufacultys =document.getElementById("stufaculty").value;
stusubjects =document.getElementById("stusubject").value;
stuclasss =document.getElementById("stuclass").value;
stuenteryears =document.getElementById("stuenteryear").value;
emails =document.getElementById("email").value;
stutelephones =document.getElementById("stutelephone").value;
//在服务器端执行zhuce_ok.php
xmlHttp.open("GET","register_chk.php?online_regname="+regnames+"& online_sturealname="+sturealnames+"& online_regpwd1="+regpwd1s+"& online_stusex="+stusexs+"& online_stuquestion="+stuquestions+"& online_stuanswer="+stuanswers+"& online_stufaculty="+stufacultys+"& online_stusubject="+stusubjects+"& online_stuclass="+stuclasss+"& online_stuenteryear="+stuenteryears+"& online_email="+emails+"& online_stutelephone="+stutelephones,true);
//定义获取服务器端响应的方法
xmlHttp.onreadystatechange=handleServerResponse;
//向服务器发送请求
xmlHttp.send(null);
}else
//如果服务器忙,1秒后重试
setTimeout('process()',1000);
}
//当收到服务器端的消息时自动执行
function handleServerResponse(){
//在处理结束时进入下一步
if(xmlHttp.readystate==4){
//状态为200表示处理成功结束
if(xmlHttp.status==200){
//获取服务器端发来的XML信息
xmlResponse=xmlHttp.responseXML;
//获取XML中的文档对象(根对象)
xmlDocumentElement=xmlResponse.documentElement;
//获取第一个文档子元素的文本信息
helloMessage=xmlDocumentElement.firstChild.data;
//使用从服务器端发来的消息更新客户端显示的内容
document.getElementById("divMessage").innerHTML='<i>'+helloMessage+'</i>';
//重新开始
setTimeout('process()',1000); }else{
//如果HTTP的状态不是200表示发生错误
alert("There was a problem accessing the server:"+xmlHttp.statusText);
}
}
}
是否真的进入了判断范围内。
代码这么写是没错的,当然你上面那么多代码我也就看了这部分,其他部分看起来也没啥关系。