我在使用由 HTML 代码分隔的 PHP 中的条件语句时遇到了一些问题。这是我正在尝试编写的代码类型。这是一个个人资料页面,只有拥有个人资料的用户才能看到它(我正在使用 session 变量来检查):
<?php if(check if user is logged in) ?>
<display users profile in html>
<?php else ?>
<display an error>
但这行不通。我还尝试通过在 if
末尾放置一个 :
并使用 endif
语句来使用速记符号,但它没有用. (在早期的项目中,:
方法适用于 foreach
和 endforeach
,所以我想我会尝试一下)
有什么想法吗?
最佳答案
您可能忘记了 alternative control structure syntax 的 endif
:
<?php if(check if user is logged in): ?>
<display users profile in html>
<?php else: ?>
<display an error>
<?php endif; ?>
在你写的时候省略大括号是不可能的。仅当其后跟一个 regular statement 时才有可能.
关于php - HTML 代码之间的 PHP 代码中的条件语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3812526/