PHP中文网为什么不能注册,用户注册验证
发布日期:2021-08-19 23:05:06 浏览次数:12 分类:技术文章

本文共 1800 字,大约阅读时间需要 6 分钟。

摘要:HTML代码html>

HTML代码html>

注册页面

邮箱:

密码:

注册

$('button').click(function(){

if ($('#email').val().length === 0) {

$('#email').after('邮箱不能为空').next().fadeOut(2000);

$('#email').focus();

return false;

}

if ($('#password').val().length === 0) {

$('#password').after('密码不能为空').next().fadeOut(2000);

$('#password').focus();

return false;

} else if($('#password').val().length 

$('#password').after('密码不能少于6位').next().fadeOut(2000);

$('#password').focus();

return false;

}

$.ajax({

type: 'post',   // 请求类型

url: 'check.php',   // 请求的处理脚本

data: {

email: $('#email').val(),

password: $('#password').val()

},

dataType: 'json',

success: function(data,status,xhr) {

console.log($(this));

// console.log(data.message);

if (data.status === 1) {

$('#email').after('').next().html(data.message).fadeOut(2000);

}else {

$('button').after('').next().html(data.message).fadeOut(2000);

}

}

});

})

PHP代码<?php

//连接数据库

$db=@mysqli_connect('127.0.0.1','root','root','phpcn',3306);

if(!$db){

exit('数据库连接错误:'.mysqli_connect_error());

}

$email = htmlspecialchars(trim($_POST['email']));

$password = htmlspecialchars(trim($_POST['password']));

$res=count_number($db,'admin','email',"$email");

if ($res) {

$status = 1;

$message = '该邮箱已注册!';

}else{

$sql="INSERT INTO `admin` (email,password) VALUES ('{$email}','{$password}')";

$return=mysqli_query($db,$sql);

if($return){

$status = 0;

$message = '注册成功!';

}else{

$status=0;

$message ='注册失败!';

}

}

mysqli_close($db);

echo json_encode(['status' => $status, 'message' => $message]);

function count_number($db,$table,$value,$key){

$sql="SELECT COUNT(*) AS count_number FROM ".$table." WHERE ".$value.'="'.$key.'"';

$return=mysqli_query($db,$sql);

$return=mysqli_fetch_assoc($return);

return $return['count_number'];

}

批改老师:欧阳批改时间:2019-05-05 09:08:12

老师总结:完成的不错。以后都用pdo进行查询了,但是也要了解下mysqli。继续加油。

转载地址:https://blog.csdn.net/weixin_31068553/article/details/115887952 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:php tab效果,jQuery_动感效果的TAB选项卡jquery 插件,效果图:动感效果的TAB选项卡 jq - phpStudy...
下一篇:加载php,在javascript中加载php页面

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年12月25日 16时03分47秒