Having trouble displaying variables. [SOLVED]
Basically i store their username when they log in and want their control panel to say Hello welcome back [username goes here].
But for some reason i can't get it to work.
This is the code i am using.
(To see if the have logged in i use a variable).
Code:
<?
If ($_SESSION[login]=1){
print($_SESSION[user]);
} else {
echo 'Not logged in';
}
?>
Before you ask me to check the variable, if i use this code it returns the message (Welcome back Scott).
Code:
<?
If ($_SESSION[user]=Scott){
print('Welcome back Scott');
} else {
echo 'Not logged in as Scott';
}
?>
Any help would be appreciated.
Re: Having trouble displaying variables.
If you are doing a comparision you need to use the "==" operator. In PHP, = is the assignment operator.
The following will always evaluate to true and execute the echo statement because $var = 1 assigns 1 to the variable $var beforethe if statment is evaluated.
PHP Code:
$var = 0;
if ($var = 1)
{
echo 'TRUE';
}
The correct way is as follows:
PHP Code:
$var = 0;
if ($var == 1)
{
echo 'TRUE';
}
Re: Having trouble displaying variables.
Ok thanks. So it is a bit like C++ then.
Re: Having trouble displaying variables.
Quote:
Originally Posted by machinist
Ok thanks. So it is a bit like C++ then.
Yes, PHP is based on C I think :)
It has a lot in common with C (And a lot different too)
Have a look here, this is the PHP homepage :D
http://www.php.net/manual/en/tutorial.php
And remember if your thread has been solved, edit your original post and add Resolved to the title and a green checkmark as its icon so others know this thread is solved :)
Cheers,
RyanJ