实际上做我见过很多PHP函数&许多PHP脚本,我总是觉得什么是真正的错误在PHP
function check() {
if(isset($_POST['example'])){
return true;
} else {
return false;
}
}
是什么真的假&办? false是否会阻止查询进一步执行?
其实我已经在这里我想停止执行,如果用户没有在数据库中找到喜欢的登录页面:
if(mysqli_num_rows($query) !=1) {
// if result is not 1 then executing must be stop here, hello should not be echo
}
echo "hello";
进一步下跌是多个脚本,只有当结果为1
应该执行据http://php.net/manual/en/function.return.php - for those of you who think that using return in a script is the same as using exit note that: using return just exits the execution of the current script, exit the whole execution.
所以我尝试了代码在我的本地
$a = 1;
if($a == 0){
echo "Its 0"; }
else{ return; }
echo "hi";
拧返回false单词后喜不执行&当我删除返回false则喜字被执行
现在,我会告诉你我真的想知道
$query3 =mysqli_query($connecDB, "SELECT * FROM users WHERE username='$username'");
if(mysqli_num_rows($query3) != 1)
{
$er1 = "Username doesn't exist";
}
else{
$query4 ="SELECT * FROM users WHERE email='$email'";
$result1=mysqli_query($connecDB, $query3);
if(mysqli_num_rows($result1) != 1)
{
$er1 = "Email doesn't exist";
} else {
// do this
}
}
现在你见上面我已经使用,如果语句成其他语句和更多,如果声明到其他,这使得我的PHP脚本非常复杂&很难理解
我只是想知道什么是bett呃像图所示
$query3 =mysqli_query($connecDB, "SELECT * FROM users WHERE username='$username'");
if(mysqli_num_rows($query3) != 1)
{
$er1 = "Username doesn't exist";
}
else{ // stop the execution here & just print this $er1 on the page without exit or die }
的方式来执行脚本我想停下来,因为下面的例子
$a = 1;
if($a == 0){
echo "Its 0 "; }
else{ //if it's not 0 then it means user is not registered do not echo echo hi below }
echo "hi";
现在喜总是执行
这一切都在手册http://php.net/manual/en/function.return。php –
在你以后的情况下,你可以使用if(check()){然后你有$ _POST ['example']设置并且可以执行一些其他需要这个变量的脚本}。如果您使用DRY编程方法 –
'exit'并且die()会停止执行,那么使用这些函数总是更好。 –