SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Session

  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session

    I want to start a session when a user logs in and to register his email for later use, but I do not know where to place session_start() and session_register("email") in the following script. When I place session_start() at the beginning of the script, it stops working.
    I would appreciate your suggestions. Thank you.

    <?

    $connection = @mysql_connect("localhost")
    or die("Couldn't connect.");

    $db = mysql_select_db("lo", $connection)
    or die("Couldn't select database.");

    $sql = "SELECT email FROM users
    WHERE email = '$email' AND
    password = password('$password')";

    $result = mysql_query($sql, $connection)
    or die("Couldn't execute query.");

    $num = mysql_numrows($result);

    if ($num == 0)
    {
    header("Location: http://localhost/error.html");
    exit;
    }
    else
    {
    header("Location: http://localhost/list.php");
    exit;
    }
    ?>

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Session

    you should place session_start() at the beginning of the script... what error message does it give you?

    as for session_register("email"), $email should already exist before you can register it as a session variable... it shouldn't be in this script since i assume your intending to use the registered $email variable...
    PHP Code:
    <?
    session_start
    ();

    $connection = @mysql_connect("localhost")  
        or die(
    "Couldn't connect."); 

    $db mysql_select_db("lo"$connection
        or die(
    "Couldn't select database."); 

    $sql "SELECT email FROM users
                WHERE email = '
    $email' AND
    // ... rest of script
    ?>


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
  •