Results 1 to 5 of 5

Thread: Basic

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220

    Basic

    Hi, i am having a few problems i have only just started php

    but could you take a look at this and tell me why its not pulling the $username from the database

    Many Thanks

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <?PHP
    $username 
    $HTTP_SESSION_VARS['username'];
    ?>
    <body>
    <h1>Well Done</h1><br>
    <?php echo"$username?> is <font color="#FF0000">logged in</font>
    </body>
    </html>
    Thanks again

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    do you really want it to get the data from a database? if so try out this page to learn how to do that.
    Have I helped you? Please Rate my posts.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2004
    Posts
    220
    no i have already connected to a the database in the previous page,but for some reason i cant load the variable into this page ? :S

    do you want to see my login_auth page. (the one that links to this page)

    Thank Adam

  4. #4
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    well. I'm no expert on mySQL, but the code that creates that variable would be handy.
    Have I helped you? Please Rate my posts.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    First off, $HTTP_SESSION_VARS is deprected in PHP 4.1 and up, so use $_SESSION instead if you're using a recent version.

    You also need to start the sessions using session_start(). Here's an example:

    Code:
    session_start(); // you must do this before any output to the browser
    
    if (isset($_SESSION['username'])) {
        echo 'Welcome back, <b>' . $_SESSION['username'] . '</b>.';
    } else {
        echo 'You are not logged in.';
    }
    To start the session:

    Code:
    session_start(); // you must do this before any output to the browser
    
    // I'm going to assume you got some login information
    // from a database and use $user as the database record:
    if ($user = mysql_fetch_array($users)) {
        $_SESSION['username'] = $user['name'];
    } else {
        echo 'Invalid information';
    }
    Then, until the browser closes, $_SESSION['username'] should be there, as the session ID is stored either in a cookie on the users computer, or passed along in the query string.

    Hope this helped.
    My evil laugh has a squeak in it.

    kristopherwilson.com

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