Page 1 of 1

$username not showing up.

Posted: Sat Nov 14, 2009 5:43 pm
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

Re: $username not showing up.

Posted: Sat Nov 14, 2009 5:58 pm
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;
?>

Re: $username not showing up.

Posted: Sat Nov 14, 2009 5:59 pm
by Kevin01926
No, i understand that, I had it work withought the <div> tags and tha <p> tags. Any clue how to fix this?

Re: $username not showing up.

Posted: Sat Nov 14, 2009 6:34 pm
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";