SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A sessions problem. My script can't read variables assigned by sessions.

    Okay, here is the script I am writing, in its most basic oif basic forms.

    php1.php
    PHP Code:
    <?php
    if (session_is_registered("session") != FALSE) {
        echo 
    $username;
    } else {
        echo 
    "<form action=\"php2.php\" method=\"POST\">";
        echo 
    "Username: <input type=\"text\" name=\"username\" value=\"\"><br />";
        echo 
    "Password: <input type=\"text\" name=\"password\" value=\"\"><br />";
        echo 
    "<input type=\"submit\" value=\"Login\">";
        echo 
    "</form>";
    }
    ?>
    php2.php
    PHP Code:
    <?php
    mysql_connect
    ("localhost","root","");
    mysql_select_db("aliennews");

    $query_users_table mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password'");
    $number_of_results mysql_num_rows($query_users_table);
    if (
    $number_of_results == "1") {
        
    session_start('session');
        
    session_register("username");
        
    header('Location: php1.php');
        exit;
    } else {
        echo 
    "Incorrect login";
    }
    ?>
    Can anyone explain to me what that code isn't working?

  2. #2
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u need
    session_start('session');

    in php1

  3. #3
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, it works now.


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
  •