用户名:
密码:
确认密码:
邮箱:
手机:
固定电话:
邮编:
地址:
php验证
header("content-type:text/html;charset=utf-8");
//print_r($_POST);die;
$name=$_POST['name'];
if($name==""){
alert("用户名不可以为空");
return false;
}
//echo $name;
$link = @mysql_connect('127.0.0.1','root','root') or die('数据库连接失败');
mysql_select_db('demo',$link) or die('选择数据库失败');
mysql_query('set names utf8');
$pwd=$_POST['pwd'];
if($pwd==""){
alert("密码不可以为空");
die;
}
$pwd1=$_POST['pwd1'];
if($pwd1==""){
alert("确认密码不可以为空");
die;
}
if($pwd!=$pwd1){
echo "";
die;
}
$email=$_POST['email'];
if($email==""){
alert("邮箱不能为空");
die;
}
if(!preg_match("/^\w+@\w+(\.)\w+$/i",$email)){
echo "邮箱格式错误!!";die;
}
$phone=$_POST['phone'];
if($phone==""){
echo "手机不能为空";
die;
}
if(!preg_match("/^1[3,5,8]\d{9}$/i",$phone)){
echo "手机号格式不正确";
die;
}
$tel=$_POST['tel'];
/*if($tel==""){
echo "电话不能为空";
die;
}
if(!preg_match("/^0\d+-\d+$/i",$tel)){
echo "电话格式不正确";
die;
}
*/
$you=$_POST['you'];
if($you==""){
echo "邮编不能为空";
die;
}
if(!preg_match("/^\d{6}$/i",$you)){
echo "邮编长度不正确";
die;
}
$address=$_POST['address'];
if($address==""){
echo "地址不能为空";
die;
}
if(!preg_match("/^\w{5,}$/i",$address)){
echo "地址不符合要求";
die;
}
$sql="insert into users(name,pwd,pwd1,phone,tel,you,address,email) values('$name','$pwd','$pwd1','$phone','$tel','$you','$address','$email')";
//echo $sql;
$res = mysql_query($sql);
if($res){
echo "";
}else{
echo "";
}
echo mysql_error();
?>
验证用户名唯一
header("content-type:text/html;charset=utf-8");
$name=$_GET['name'];
//操作数据库
$link=mysql_connect("127.0.0.1","root","root") or die("连接数据库失败");
//选择数据库
mysql_select_db("demo",$link) or die("选择数据库失败");
//设置字符集
mysql_query("set names utf8");
$sql="select * from users where name='$name'";
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
if($row)
{
echo "名称重复";die;
}
else
{
echo "名称可用";die;
}
?>