gpt4 book ai didi

php - 停止 if 子句以及整个 PHP 脚本,但不停止 HTML

转载 作者:行者123 更新时间:2023-12-03 23:06:43 25 4
gpt4 key购买 nike

我已经遇到这个问题大约一个小时了,并在互联网上搜索答案。我检查了 PHP 文档,环顾四周,谷歌搜索,一无所获。

无论如何,我的问题是,在我尝试验证某些内容(并且这是错误的)之后,如果我使用exit;,它也会在之后停止HTML。这就是我要说的:

if ($_POST['exampleEmail'] == "")
{
echo "Please enter an e-mail."; //Now I want only the PHP script to stop, however...
exit; //If I use exit, then the HTML after this script (footer) doesn't show.
}

如果有人可以帮忙,请帮忙。我尝试过使用break,但无济于事,因为它仅适用于循环和开关。

如果有更好/更正确的方法(或者如果这是错误的方法,则只是更正),请分享。我过去也遇到过这个问题,然后我就使用了 exit。

谢谢。

最佳答案

只需将脚本的其余部分包装在新的 if block 中即可:

$execute = true;

// HTML here...
if (empty($_POST['exampleEmail'])) {
echo "Please enter an e-mail.";
$execute = false;
}
// HTML here...
if ($execute) {
// do stuff only if execute is still true.
}
// HTML here...

既然这对你有用,我建议你做一些研究来分离你的演示和逻辑。有很多关于该主题的教程和博客,您只需要开始搜索即可。

关于php - 停止 if 子句以及整个 PHP 脚本,但不停止 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5067678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com