1

I'm quite new to PHP and I've written a login script to go on my website. I can manage to style the text from my stylesheet but the username session variable I'm unable to style, how would I apply a css style to it?

My code is below...

<?php
        if (isset($_SESSION["signedin"])){
            echo '<a href="logout.php" class="subheading">Log Out</a>';
            echo " ".$_SESSION["username"];
            }
            else {
                echo '<a href="login.php" class="subheading">Login</a>';
            }
    ?>

I have a style called para2 in my stylesheet which I'd like the returned username to be styled in but I can't get it to work without throwing up an error, or the page ignoring the class that's assigned to it and it defaulting to the regular blue text of the browser.

Thanks

2
  • 1
    Can you post the css that you have written for this too please Commented Mar 10, 2015 at 0:19
  • Oh magic crystal ball, reveal unto us this elusive "error" OP speaketh of Commented Mar 10, 2015 at 0:26

2 Answers 2

3

Why not put paragraph tags around the username so you can style the text. e.g.

  echo '<p class="para2"> '.$_SESSION["username"].'</p>';
Sign up to request clarification or add additional context in comments.

5 Comments

Why mix quotes like that? Even OP is using single-quotes
Ok, now you've just made it worse
echo '<p class="para2">'
@Phil that works but puts the username on a separate line. how would I be able to keep it on the same line as where it says logout?
use <SPAN> instead of <P> OR update your para2 style to display:inline;
2

Add this to your css:

a.subheading   {
    color: #333; /* change color accordingly */
}

5 Comments

Do post the css too so I can provide a more specific answer for your problem
.heading2{ color:grey; font-size:24px; text-align:left; font-family:"helvetica neue"; padding-top:4px; } .subheading{ color: #a685dd; font-size:24px; font-family:"helvetica neue"; } .subheading2{ color:grey; font-size:18px; } .para{ font-family:"helvetica"; font-size:20px; } .para2{ font-family:"helvetica neue"; font-size:15px; color:#606060; } .para3{ font-family:"georgia"; font-size:12px; color:grey; } .headertext{ font-family:"calibri"; font-size:18px; color:blue; } a.subheading:link { font-size: 15px; font-style: italic; }
@zxcv5 ... to your question
Add the above to your css and it should work fine. You can add an !important just in case some other css is overriding it like this color: #333 !important;
@AndrewLyndem thanks for your help Andrew, got it sorted out now. I've still a lot to learn! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.