<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>购物注册</title>
<script src="../JS/jquery-1.8.2.min.js"></script>
</head>
<body>
<div>用户名: <input type="text" id="uid" /><span id="kk"></span></div>
<div>密 码: <input type="text" id="pwd" /></div>
<div>姓 名: <input type="text" id="name" /></div>
<div><input type="button" value="注册" id="zhuce"/></div>
</body>
</html>
<script>
$("#uid").blur(function(){
var uid = $(this).val();//回调函数
$.ajax({
url:"Gchakan.php", //处理页面的路径
data:{uid:uid}, //要提交的数据是一个JSON
type:"POST", //提交方式
dataType:"TEXT", //返回数据的类型
//TEXT字符串 JSON返回JSON XML返回X
success:function(kiss){ //回调函数
if(kiss.trim()=="no")
{
$("#kk").html("该用户名可用");
$("#kk").css("color","green");
}
else
{
$("#kk").html("该用户名不可用");
$("#kk").css("color","red");
}
}
})
})
$("#zhuce").click(function(){
var u =$("#uid").val();
var p =$("#pwd").val();
var n =$("#name").val();
$.ajax({
url:"Gzc.php",
data:{u:u,p:p,n:n},
type:"POST",
dataType:"text",
success: function(data){
if(data.trim()=="ok")
{
alert("注册成功");
}
else
{
alert("注册失败");
}
}
})
})
</script>
查看用户名是否注册
<?php
$uid = $_POST["uid"];
require "Wxk.class.php";
$db =new Wxk();
$sql = " select count(*) from login where UserName = '{$uid}'";
$arr = $db->query($sql);
$arr[0][0];
if($arr[0][0])
{
echo "ok";
}
else
{
echo "no";
}
注册写入处理页面
<?php
require "Wxk.class.php";
$db =new Wxk();
$uid = $_POST["u"];
$pwd = $_POST["p"];
$name = $_POST["n"];
$sql = "insert into login values('{$uid}','{$name}','{$pwd}',100)";
if($db->query($sql,0))
{
echo "ok";
}
else
{
echo "no";
}