SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jul 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why my session variable is empty

    Hello i got a problem trying to make a login in my code, my $_SESSION variable
    is always empty, and if i try to print it with echo , i got a erro msg say that my
    _SESSION variable is not defined.

    Here is my code, im using PHP 5.0.4 and apache 2.0.54 on Windows XP professional.

    Login.html
    HTML Code:
    <?
      start_session();
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    
      <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
      <title>Login</title>
    
    
    </head>
    
    
    <body>
    
    <br>
    
    <form method="post" action="loginverify.php" name="login">
    
      User <input name="fieldUser">
      Pass <input name="fieldPass" type="password">
      <button value="Submit" name="Enter">enter</button>
      <button value="Reset" name="reset">Reset</button>
    
    </form>
    
    </body>
    
    </html>
    loginverify.php
    PHP Code:
    <?

    $conn 
    mysql_connect('localhost''root''') or die ('Database Erro.');

    mysql_select_db('MANAGER');

    $sql "SELECT ID_CLIE , NAME FROM CLIENTS WHERE EMAIL = '" $_POST["fieldUser"] . "' AND PASS = '" .  $_POST["fieldPass"] . "'" ;

    $query mysql_query$sql );

    if( 
    mysql_num_rows$query ) )
    {
      
    $nome mysql_result($query,0,"name");
      
    $clienteID mysql_result($query,0,"id_clie");


      
    $_SESSION['name'] = $nome;
      
    $_SESSION['id_clie'] = $clienteID;
      
    Header("location:products.php");
    }
    else
    {
      echo 
    'Login error, try again!';  
    }

    mysql_close$conn );

    ?>
    products.php
    PHP Code:
     <?
        
    if( !empty( $_SESSION['name'] ) AND !empty( $_SESSION['id_clie'] ) )
        {
          echo 
    'OK!';
        }
        else
        {
          echo 
    'Login please.';

        }
     
    ?>
    Thank you for your help

    Jean

  2. #2
    SitePoint Enthusiast shref's Avatar
    Join Date
    Nov 2004
    Location
    Egypt, Alexandria
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use start_session();
    in the first of loginverify.php
    Shreef
    blog: shreef.com
    twitter: @shreef


Bookmarks

Posting Permissions

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