php Ajax 无法登陆
无法注册,不能弹出注册成功的窗口,数据库没有增加新用户,
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发的数据是不是完整和对的
找不出毛病,就怪我代码没给全,我才擦呢,再也不来了,一堆没耐心的家伙,态度越来越差了,什么东西都没解答出来吃干饭,恶心死了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.
