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?
session_start();<h2>elements read whether or not the user is logged in or not and if so reads their username which is already inside php...<h>tag can accept some additional parameters, from what I've done before, maybe not in conjunction with PHP, but if the intention is to use PHP inside your<h2>tag, then you could probably use<h2 <?php // code >Text</h2>but that's untested of course ;-)