How do i put div tag in my example echo here?

 if ($_SESSION['username'])
 {
 echo "you are logged in as: ".$_SESSION['username'];
 }

I want to put style(css)on that $_SESSION(username) whoever logins. For example, you are logged in as: Sam
I want to style the name Sam.

If you only want to adjust the name, I suggest:

echo 'you are logged in as: <span id="username">' . $_SESSION['username'] . '</span>';

then you can style using span#username. There are many more options of course.

i tried your code and got an error Unexpected T_STRING. I tried rearranging quotation marks if thats the problem but still displaying an error. What are the other option you know?

This is my code:

<?php

session_start();

if ($_SESSION['username'])
{
 echo "You are logged in as: " .$_SESSION['username'];
 echo "<p>";
 echo "<a href='logout.php'>Log out</a>";
}
else
    header("location: index.php");
?>

As you can see, there's no div or span tag as i can't figure it out on how/where to put it as it display an error.

What I meant was, show the code that gave the error (and the error message). You must have missed a quote.

Dude! It's working! I tried again your code and it works. I don't know but i did the same thing awhile ago.. I think i don't need now to post the code? Thank you so much!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.