0

I have a php code in a div but I want the username show after the user has logged in but how could I echo a session inside an echo?

<?php
            if(isset($_SESSION['username']))
            {
                echo '<ul class="nav" action="Login.html" method="post">
                    <li class="loginbtn"><a href="#">echo '$_SESSION['username'];'</a></li>
                    <li class="loginbtn"><a href="#">Logout</a></li>
                    </ul>';
                    }
game symbol
  • 135
  • 2
  • 10
  • if the session array contains value, then that should work (Edit: see the latter part of my comment). If not, assign value to it and start the session. Btw, you have a parse error here, which would throw `unexpected T_ECHO`. – Funk Forty Niner Aug 03 '18 at 15:00
  • oic, thanks bro the problem solved ! – game symbol Aug 03 '18 at 15:13

1 Answers1

1

Use concatenation

echo '<ul class="nav" action="Login.html" method="post">
                <li class="loginbtn"><a href="#">'.$_SESSION['username'].'</a></li>
                <li class="loginbtn"><a href="#">Logout</a></li>
      </ul>';

You don't need to call echo again and you don't need a semicolon

No Name
  • 612
  • 6
  • 15