php与ajax用户名验证

checkuserreg.php

header('Content-Type:text/html;charset=GB2312');//避免输出乱码
$dbhost     = "localhost";
$dbuser     = "root";
$dbpassword = "root";
$dbname     = "member";
mysql_connect($dbhost,$dbuser,$dbpassword) or die("error!");
mysql_query("set names 'gbk'");
mysql_select_db($dbname);

$username=trim($_POST['username']);//获取注册名
$sql="select username from member where username='$username'";//查询会员名
$result=mysql_query($sql);
$num=mysql_num_rows($result);
//$rows=mysql_fetch_array($result);
if($num<>0){
          echo "此会员名已被注册,请更换会员名!";
}
else{
          echo "此会员名可以注册!";
}
mysql_close();//关闭数据库连接 
?>

login.html








            
       
       
       
                                            

用户名称: 
                  
         
4-16个字符,英文小写、汉字、数字、最好不要全部是数字。



数据类型表member

字段:id , username

你可能感兴趣的:(php)