March 9, 2013
Stop code after if statment from excuting when error occurs
Question by shnisaka
This is what my code looks like:
if($allthevaluesarenotempty) {
if($pictureexist) {
// upload picture code
}
else
{
$message = "error";
}
// sql query here
}
How can I stop the SQL query from executing when $message is set?
Answer by Starx
-
If in case of loops like while, for and foreach, you can use
continue;to escape the iteration andbreak;to end the loop. -
In function
return false;will stop the execution. -
In a PHP document,
exit()will terminate further execution of the script.
So, use which is suitable.