$username not showing up.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kevin01926
Forum Newbie
Posts: 2
Joined: Sat Nov 14, 2009 5:35 pm

$username not showing up.

Post by Kevin01926 »

Ok so i have created a login system. When a user is logged in, i echo "Hello John, Welcome!"

However, when i inserted some CSS style, it literally says:

Code: Select all

Hello $username, Welcome!
[/color]

Any clue?

Oh, and the code:

Code: Select all

 
 
 echo ' <div id="status"><p class="stat"> Welcome <b>$username</b>, <a href=users.php>Manage Account</a>, <a href=users.php?maa=Logout>Logout</a></p> </div>';
 
 
 
Thanks
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: $username not showing up.

Post by JAB Creations »

Code: Select all

<?php
$name = 'Hank';
 
echo 'Hi $name'; // Hi $name
echo "Hi $name"; // Hi Hank
?>
...also I've read that using double quotes adds a little extra load on the server so you may want to use concatenation as so...

Code: Select all

<?php
$name = 'Hank';
 
echo 'Hi '.$name;
?>
Kevin01926
Forum Newbie
Posts: 2
Joined: Sat Nov 14, 2009 5:35 pm

Re: $username not showing up.

Post by Kevin01926 »

No, i understand that, I had it work withought the <div> tags and tha <p> tags. Any clue how to fix this?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: $username not showing up.

Post by John Cartwright »

Kevin01926 wrote:No, i understand that, I had it work withought the <div> tags and tha <p> tags. Any clue how to fix this?
I don't think you fully understand. Again.. variables will NOT be evaluated inside single quotes. Either you must escape the single quotes, or use double quotes. It is my personal preference to use single quotes and escape for variables as it is more readable.

Code: Select all

 
//invalids
$foo = 'This $variable will not be parsed';
 
//valids
$foo = 'This '. $variable .' will be parsed';
$foo = "This $variable will be parsed";
$foo = "This ". $variable ." will be parsed";
Post Reply