作者:手机用户2502902993 | 来源:互联网 | 2017-05-14 02:19
html代码输入框:
js检测(仅列出jquery判断用户名的代码):
$(document).ready(function(){
//判断用户名是否已经注册了
$('#username').blur(function() {
if ($('#username').val() != '') {
$.post('chkname.php', {username : $('#username').val()}, function(data) {
if (data == 0) {
$('#notice1').html('抱歉,该用户名已经被占用!').css('color', 'red');
} else {
$('#notice1').html('该用户名可以被注册!').css('color', '#00FFEC');
}
});
}
});
//验证邮箱密码等信息
$('#submit').click(function(){
//验证邮箱的格式和信息
if($('#username').val()=='') {
$('#notice1').html("用户名不能为空!").css('color','red');
return false;
}
)};
php端代码:chkname.php(根据后台其他功能显示判定smarty模板已经生效,且数据库连接正确)
回复内容:
html代码输入框:
js检测(仅列出jquery判断用户名的代码):
$(document).ready(function(){
//判断用户名是否已经注册了
$('#username').blur(function() {
if ($('#username').val() != '') {
$.post('chkname.php', {username : $('#username').val()}, function(data) {
if (data == 0) {
$('#notice1').html('抱歉,该用户名已经被占用!').css('color', 'red');
} else {
$('#notice1').html('该用户名可以被注册!').css('color', '#00FFEC');
}
});
}
});
//验证邮箱密码等信息
$('#submit').click(function(){
//验证邮箱的格式和信息
if($('#username').val()=='') {
$('#notice1').html("用户名不能为空!").css('color','red');
return false;
}
)};
php端代码:chkname.php(根据后台其他功能显示判定smarty模板已经生效,且数据库连接正确)
php
//建议使用pdo
$sql="select * from admin_users where username='".$_POST['username']."'";
$re=mysql_query($sql);
if (mysql_num_rows($re) == 0) {
echo 1; //用户合法
exit;
} esle {
echo 0; //用户不合法
exit;
}