HTML代码之间的PHP代码中的条件语句 [英] Conditional Statements in PHP code Between HTML Code

查看:97
本文介绍了HTML代码之间的PHP代码中的条件语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用HTML中的条件语句分隔HTML代码,我遇到了一些问题。这是我正在编写的代码类型。这是一个配置文件页面,它应该只能被用户的配置文件看到(我使用会话变量来检查它):

 <?php if(检查用户是否登录)?> 
<在html中显示用户个人资料>
<?php else?>
<显示错误>

但这不起作用。我还尝试在结尾放置一个并使用来使用简写符号c> endif 语句,但它不起作用。 (在之前的项目中,方法适用于 foreach endforeach 所以我想我会试试看)



任何想法? 您可能已经忘记了 endif http://php.net/control-structures.alternative-syntaxrel =noreferrer>替代控制结构语法

 <?php if(检查用户是否登录):?> 
<在html中显示用户个人资料>
<?php else:?>
<显示错误>
<?php endif; ?>

省略大写字母是不可能的。只有紧随其后的是正式声明


I'm having a bit of an issue by using Conditional Statements in PHP separated by HTML code. This is the type of code I'm trying to write. This is a profile page and it should only be seen by the user whose profile it is (i'm using session variables for checking that) :

<?php if(check if user is logged in) ?>
<display users profile in html>
<?php else ?>
<display an error>

But this doesn't work. I also tried using the shorthand notation by putting a : at the end of the if and using the endif statement, but it didn't work. ( On an earlier project , the : method worked for foreach and endforeach so I thought I would try it out )

Any Ideas ?

解决方案

You probably forgot the endif of the alternative control structure syntax:

<?php if(check if user is logged in): ?>
<display users profile in html>
<?php else: ?>
<display an error>
<?php endif; ?>

Omitting the braces as you wrote is not possible. It is only possible if it is followed by a regular statement.

这篇关于HTML代码之间的PHP代码中的条件语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆