Results 1 to 4 of 4

Thread: Having trouble displaying variables. [SOLVED]

  1. #1

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    Resolved 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

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    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';

    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2004
    Location
    Where i am
    Posts
    38

    Re: Having trouble displaying variables.

    Ok thanks. So it is a bit like C++ then.

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    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
    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
    My Blog.

    Ryan Jones.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width