I am having an issue with my php and html. I understand the concept that once <?php ;?>
is open you cannot put another line such as <?php ;?>
inside that making it look like <?php <?php ;?> ;?>
as it throws errors, and if not, it does on my end... Same goes that I understand that using echo
, print
etc. is more or less what I'm after. My dilemma here is that how would I structure this if using sessions? This is what I have so far, all of which is inside the <body>
tag:
<?php echo $_SESSION['id']?'
<div id="top_mid">
<h2><?php echo $_SESSION['username'] ? $_SESSION['username'] : 'Guest';?></h2>
</div>':'
<h2>
<li id="toggle" style="list-style: none;">
<p>Please <a id="open" class="open" href="#open">Login | Register</a>
<a id="close" style="display: none;" class="close" href="#close">Login | Register</a> to access this page!
</p>
</h2>';
?>
As you can note, this line: <h2><?php echo $_SESSION['username'] ? $_SESSION['username'] : 'Guest';?></h2>
is what is throwing me errors since it is already inside a previous <?php ;?>
statement...
I've tried using <h2>echo "$_SESSION['username'] ? $_SESSION['username'] : 'Guest';"</h2>
but that doesn't work either...any help would be much appreciated...
Would I need to create a variable for that session username? So for example:
$username = "<?php echo $_SESSION['username'] ? $_SESSION['username'] : 'Guest';?>";
and then place that inside the <h2>
element? If so, how would I restructure that to make it work since I've tried that and it throws me errors?
` elements read whether or not the user is logged in or not and if so reads their username which is already inside php...
– user2732875 Dec 19 '13 at 20:16` tag, then you could probably use `
Text
` but that's untested of course ;-)` tag inside another php thing already...
– user2732875 Dec 19 '13 at 20:19>
` which "could" work, but again, un-tested. – Funk Forty Niner Dec 19 '13 at 20:20` tag like that?
– user2732875 Dec 19 '13 at 20:34