为什么不满足条件 还是进入if 输出了用户名格式异常QAQ

WBOY
Release: 2016-06-13 12:59:59
Original
959 people have browsed it

为什么不满足条件 还是进入if 输出了用户名格式错误QAQ
进入格式检查 个个变量的值


可是strlen($username)=9
result1=1
还是会跑进if里面
输出用户名格式错误


整段代码里只有这一段“用户名格式错误”
[/img]

<br />
<?php<br />
$posts=$_POST;<br />
foreach($posts as $key => $value){<br />
	if(empty($value))<br />
		exit('非法访问!');<br />
}<br />
foreach ($posts as $key => $value) {<br />
	$posts[$key] = trim($value);<br />
}<br />
require ('dbconfig.php');<br />
//注册<br />
function register($username,$password,$email){<br />
	$query = "insert userdata values('". $username ."','". $password ."','". $email. "')";<br />
	$result=mysql_query($query);<br />
	if(!$result){<br />
		exit('注册失败!papap');<br />
		//die('注册失败'.  mysql_error());<br />
	}<br />
	else{<br />
		echo "注册成功!";<br />
	}<br />
}<br />
//检查用户名,密码,邮箱格式<br />
function verifyFormat($username,$password,$email){<br />
	$result1=preg_match("/^[\x{4e00}-\x{9fa5}]+$/u", $username);<br />
	if(strlen($username)<1 || strlen($username)>16 || result1==0){<br />
		echo "用户名格式错误!";<br />
		return false;<br />
		//die("用户名格式错误!");<br />
	}<br />
<br />
	$result2=preg_match("/^\w+$/u", $password);<br />
	if(strlen($password)<6 || strlen($password)>17 || result2==0){<br />
		echo "密码格式错误!";<br />
		return false;<br />
		//die("密码格式错误!");<br />
	}<br />
	<br />
	$result3=preg_match("/^[a-zA-Z\d]+@[a-zA-Z\d]+\.[com|cn|com.cn|net]+$/u", $email);<br />
	if(result3==0){<br />
		echo "邮箱格式错误!";<br />
		return false;<br />
		//die("邮箱格式错误!");<br />
	}<br />
	return true;<br />
}<br />
$flag=verifyFormat($posts['username'],$posts['password'], $posts['email']);<br />
if($flag)<br />
	register($posts['username'],$posts['password'], $posts['email']);<br />
else<br />
	die("注册失败!!..");<br />
?><br />
Copy after login



------解决方案--------------------
斑竹说的对。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template