我一直在为一个网站编写一个注册脚本,它按顺序检查每个字段的输入(总共 9 个),一旦所有这些都被检查过,它就会在"{//9"
和之间完成代码"}// close9"
。
但是,如果任何检查失败,脚本应该为变量分配一个“失败”的值$GLOBALS['fail']
,这反过来又应该在页面底部返回回显“注册失败”。
但是,即使为$GLOBALS['fail']
变量分配了一个值,passed
它仍然会回显“注册失败”,尽管我已经尝试了一切,但它不会停止。
我什至输入了在调用函数之前echo $GLOBALS['fail'];
检查它分配的值。if($GLOBALS['fail'] = "failed")
下面是代码:
<?php
//first visit
if(isset($_POST['submit']))
{//first visit
if(isset($_POST['firstname'])&&(!empty($_POST['firstname'])))
{//1
$firstname = $_POST['firstname'];
echo $firstname . "<br/>";
if(isset($_POST['surname'])&&(!empty($_POST['surname'])))
{//2
$surname = $_POST['surname'];
echo $surname. "<br/>";
if(isset($_POST['username'])&&(!empty($_POST['username'])))
{//3
$username = $_POST['username'];
echo $username. "<br/>";
if(isset($_POST['password1'])&&(!empty($_POST['password1'])))
{//4
$pass1 = $_POST['password1'];
echo $pass1. "<br/>";
if(isset($_POST['password2'])&&(!empty($_POST['password2'])))
{//5
$pass2 = $_POST['password2'];
echo $pass2. "<br/>";
if(isset($_POST['day'])&&(!empty($_POST['day'])))
{//6
$day = $_POST['day'];
echo $day. "<br/>";
if(isset($_POST['month'])&&(!empty($_POST['month'])))
{//7
$month = $_POST['month'];
echo $month. "<br/>";
if(isset($_POST['year'])&&(!empty($_POST['year'])))
{//8
$year = $_POST['year'];
echo $year. "<br/>";
if(isset($_POST['email'])&&(!empty($_POST['email'])))
{//9
$email = $_POST['email'];
echo $email. "<br/>" ."well done";
$GLOBALS['fail'] = "passed";
echo $GLOBALS['fail'];
} //close9
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close8
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close7
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close6
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close5
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close4
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close3
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close2
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //close1
else {$GLOBALS['fail']="failed"; echo "Please fill in <b>All</b> fields " ;}
} //firstvisit
else echo "stupidity";
echo $GLOBALS['fail'];
if(isset($GLOBALS['fail'])){
if($GLOBALS['fail']="failed"){
echo "registration failed";
}
else echo $GLOBALS['fail'];
}
else echo "no fail set";
?>
当我按下注册并且整个表单完成时屏幕上的输出很好完成通过通过注册失败
任何人都可以帮助我吗?