實際上做我見過很多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()會停止執行,那麼使用這些函數總是更好。 –