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.