首页  >  文章  >  后端开发  >  php Ajax 无法登陆

php Ajax 无法登陆

WBOY
WBOY原创
2016-06-23 14:09:27912浏览

无法注册,不能弹出注册成功的窗口,数据库没有增加新用户,
register.php

 <table border="0" align="center" cellpadding="0" cellspacing="0">		  <tr><td><p>注册名称:</p></td><td><input id="regname" name="regname" type="text" class="txt" /></td><td><div id="namediv" class="regdiv">  名称由字母及下划线组成</div></td></tr>		  <tr><td><p>注册密码:</p></td><td><input id="regpwd1" name="regpwd1" type="password" class="txt" /></td><td><div id="pwddiv1" class="regdiv">  请输入密码</div></td></tr>		  <tr><td><p>确认密码:</td><td><input id="regpwd2" name="regpwd2" type="password" class="txt" /></td><td><div id="pwddiv2" class="regdiv">  确认密码</div></td></tr>          <tr><td colspan="3"><a id="morebtn">更多.......</a><input id="chknm" name="chknm" type="hidden" value=""  /></td></tr>	</table>		      <div id="morediv" style="display:none;padding:0 0 0 57px;">	<hr />	<table border="0" cellpadding="0" cellspacing="0" id="regfm">	<tr><td style="width:70px;">密保问题:</td><td><input id="question" name="question" type="text"  /></td></tr>	<tr><td>密保答案:</td><td><input id="answer" name="answer" type="text" /></td></tr>	<tr><td>电子邮件:</td><td><input type="text" name="xuehao" id="xuehao" /></td></tr>	<tr><td>QQ号码:</td><td><input type="text" name="xuehao" id="xuehao" /></td></tr>	<tr><td>手机号码:</td><td><input type="text" name="xuehao" id="xuehao" /></td></tr>    	<tr><td>真实姓名:</td><td><input type="text" name="relname" id="relname" /></td></tr>	<tr><td>河海学号:</td><td><input type="text" name="xuehao" id="xuehao" /></td></tr>	<tr><td style="height:40px;">性别:</td><td>         		<select id="sex" name="sex">		<option value='男' selected="selected">男</option>		<option value='女'>女</option>	</select></td></tr>	<tr><td style="height:40px;">出生日期:</td><td>        <select id='year' name='year' style="width:70px;">		<option value="<?php echo date('Y'); ?>" selected="selected"><?php echo date('Y'); ?></option>	<?php	for($i=1900;$i<2024;$i++){	?>		<option value="<?php echo $i; ?>"><?php echo $i; ?></option>	<?php	}	?>	</select>  年  <select id="month" name="month">	<?php	for($i=1;$i<=12;$i++){	?>		<option value="<?php echo $i; ?>"><?php echo $i; ?></option>	<?php	}	?>	</select>  月  <select id="day" name="day">	<?php	for($i=1;$i<=31;$i++){	?>		<option value="<?php echo $i; ?>"><?php echo $i; ?></option>	<?php	}	?>	</select>  日  </td></tr>	</table>

register.js
// JavaScript Documentfunction $(id){	return document.getElementById(id);}window.onload = function(){	$('regname').focus();	var cname1,cname2,cpwd1,cpwd2;	//验证用户名	$('regname').onkeyup = function (){		name = $('regname').value;		cname2 = '';		if(name.match(/^[a-zA-Z_]*/) == ''){			$('namediv').innerHTML = '<font color=red>必须以字母和下划线开头</font>';			cname1 = '';		}else if(name.length <= 3){			$('namediv').innerHTML = '<font color=red>注册名称必须大于三位</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 = '';						}					}				}			}			xmlhttp.send(null);			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();	}	function chkreg(){		if((cname1 == 'yes') && (cname2 == 'yes') && (cpwd1 == 'yes') && (cpwd2 == 'yes')){			$('regbtn').disabled = false;		}else{			$('regbtn').disabled = true;		}	}	$('morebtn').onclick = function(){		if($('morediv').style.display == ''){			$('morediv').style.display = 'none';		}else{			$('morediv').style.display = '';		}	}	//正式注册	$('regbtn').onclick = function(){		name = $('regname').value;		pwd = $('regpwd1').value;		question1 = $('question').value;		answer1 = $('answer').value;		realname1 = $('realname').value;		xuehao1 = $('xuehao').value;		email1 = $('email').value;		qq1 = $('qq').value;		tel1 = $('tel').value;		sex1 = $('sex').value;		birthday1 = $('year').value+'-'+$('month').value+'-'+$('day').value;				url = 'register_chk.php?name='+name+'&pwd='+pwd;		url += '&question='+question1+'&answer='+answer1+'&email='+email1;		url += '&qq='+qq1+'&tel='+tel1;		url += '&realname='+realname1+'&xuehao='+xuehao1+'&sex='+sex1+'&birthday='+birthday1;		xmlhttp.open('get',url,true);		xmlhttp.onreadystatechange = function(){			if(xmlhttp.readyState == 4){				if(xmlhttp.status == 200){					msg = xmlhttp.responseText;					if(msg == '1'){						top.opener.location.reload();						alert('注册成功!');												location='yhzx.php';					}else{						alert(msg);					}				}			}		}		xmlhttp.send(null);	}}

register_chk.php
<?php	session_start();	header('Content-Type:text/html;charset=utf-8');	include_once 'conn/conn.php';	include_once '../config.php';	$reback = '0';	//echo $_GET['headgif'];		$sql = "insert into tb_users(name,pwd,question,answer,realname,xuehao,sex,tel,email,qq,birthday) values('".trim($_GET['name'])."','".md5(trim($_GET['pwd']))."','".$_GET['question']."','".$_GET['answer']."','".$_GET['realname']."','".$_GET['xuehao']."','".$_GET['sex']."','".$_GET['tel']."','".$_GET['email']."','".$_GET['qq']."','".$_GET['birthday'].'")";	$num = $conne->uidRst($sql);	if($num == 1){		$_SESSION['name'] = $_GET['name'];		$reback = '1';	}else{		$reback = $conne->msg_error();	}	echo $reback;?>

chk_name.php
<?phpsession_start();include_once "conn/conn.php";$reback = '0';$sql = "select * from tb_member where name='".$_GET['name']."'";$num = $conne->getRowsNum($sql);if($num == 1){	$reback = '2';}else if($num == 0){	$reback = '1';}else{	$reback = $conne->msg_error();}echo $reback;?>


回复讨论(解决方案)

代码太多,先告诉我们 提交上去的数据是否正确 返回结果又是什么?

你真实够可以的,连代码都不给全,怎么帮你查错?

我靠,js啊

我是来学习的

解决问题自己不急 你当比人来给你急啊 代码都不全  我擦
你可以直接抛开 ajax 先用php注册看能不能成功 在看下js发的数据是不是完整和对的

找不出毛病,就怪我代码没给全,我才擦呢,再也不来了,一堆没耐心的家伙,态度越来越差了,什么东西都没解答出来吃干饭,恶心死了。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn