|
-
May 23rd, 2005, 09:54 AM
#1
Thread Starter
Member
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.
Last edited by machinist; May 24th, 2005 at 01:25 PM.
Reason: Solved
-
May 23rd, 2005, 11:23 AM
#2
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';
}
-
May 24th, 2005, 05:42 AM
#3
Thread Starter
Member
Re: Having trouble displaying variables.
Ok thanks. So it is a bit like C++ then.
-
May 24th, 2005, 05:47 AM
#4
Re: Having trouble displaying variables.
 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 
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|