<?php header("content-type:text/html;charset=utf8"); //var_dump($_POST);die; //array(5) { ["uname"]=> string(9) "刘伟超" ["uqq"]=> string(10) "1111111111" ["uemail"]=> string(12) "66555@qq.com" ["utel"]=> string(11) "15863162320" ["uinfo"]=> string(48) "地方开始放假开放活动健康的话概括" } empty($_POST["uname"])?$uname="":$uname=$_POST["uname"]; empty($_POST["uemail"])?$uemail="":$uemail=$_POST["uemail"]; empty($_POST["utel"])?$utel="":$utel=$_POST["utel"]; empty($_POST["uqq"])?$uqq="":$uqq=$_POST["uqq"]; empty($_POST["uinfo"])?$uinfo="":$uinfo=$_POST["uinfo"]; //验证姓名 $reg="/^[\x{4e00}-\x{9fa5}]{2,3}$/u"; if(!preg_match($reg,$uname)){ echo "用户名应该2-3个汉字";die; //header("refresh:1;url=form.html"); } //验证邮箱 $reg="/^(\w+@\w+(\.)com|net|cn)$/"; if(!preg_match($reg,$uemail)){ echo "邮箱必须含有@,且以com结尾";header("refresh:1;url=form.html"); die; } //验证座机号 $reg="/^\d{11}$/"; if(!preg_match($reg,$utel)){ echo "座机号以010-22222222格式";header("refresh:1;url=form.html"); die; } //验证QQ号 $reg="/^\d{5,11}$/"; if(!preg_match($reg,$uqq)){ echo "qq必须是5-11位纯数字";header("refresh:1;url=form.html"); die; } //验证简介 /*$reg="/^[\x{4e00}-\x{9fa5}]{10,100}\W+/u"; if(!preg_match($reg,$uinfo)){ echo "简介应该10-100个汉字";die; //header("refresh:1;url=form.html"); } */ //连接数据库 $link=mysql_connect('127.0.0.1','root','root')or die("连接失败"); //选择数据库 mysql_select_db('kaoshi',$link); //设置字符集 mysql_query("set names utf8"); //写sql语句 $sql="insert into zhuce(c_name,c_qq,c_email,c_tel,c_info) values('$uname','$uqq','$uemail','$utel','$uinfo')"; //echo $sql;die; $rel=mysql_query($sql); if($rel){ echo "注册成功";header("refresh:1;url=show.php"); }else{echo "注册失败";header("refresh:1;url=form.html");} ?>
Ajax和PHP正则表达式验证表单及验证码(2)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/d4fe7b39fb1199ab97bfe2e4541833a0.html