Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error with making login page...!

    Hello, I'm fairly new to PHP (about 4 months using it).

    I'm trying to make a script for loging in, but I seem to have a error in my scripting. can you please help?

    All I get is "We're sorry, your username does not appear to be in our database." even when the username is in the database.

    Here's my Code:

    PHP Code:
    <?php

    // MySQL User Login, Copyright 2002 Acorn Webs. All Rights Reserved.
    //
    // This Script is for Acorn Webs use ONLY!
    // Includes Acorn Webs Clients.

    // Include Files

    require("includes/mysql.inc");

    // End of Include Files
    // query commands

    mysql_select_db("phpbb2"$linkID) or die(mysql_error());

    $resultID mysql_query("SELECT user_id FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

    // End of query commands
    // Check Username

    $num_rows mysql_num_rows($resultID); 
    $row mysql_fetch_array($resultID); 
    $user_id $row[0]; 

    if (
    $user_id == "") {
        print 
    "We're sorry, your username does not appear to be in our database.";
    }
    else {
    // End of Check Username
    // query and other commands

        
    $resultID mysql_query("SELECT user_password FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

        
    $encryptedpassword md5($password);
        
        
    $row mysql_fetch_array($resultID); 
        
    $passwordfromdb $row[0];
    // End of query commands
    // Check Password

        
    if ($encryptedpassword == $passwordfromdb) {
            print 
    "We're sorry, your password or username is incorrect.";
        }
        else {
            print 
    "login currect";
        }
    }

    // End of Check Password

    mysql_close($linkID);

    ?>
    I'm sure it's something so simple but I can't seem to find it.
    Thanks.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    From a first look, your code looks well done and should work alright. From the output it generates, you know already that the problem must lie somewhere in these lines:

    PHP Code:
    $row mysql_fetch_array($resultID); 
    $user_id $row[0]; 

    if (
    $user_id == "") { 
    Which further indicates, that there is either no appropriate data in the database or the query was somehow malformed. I would suggest narrowing the problem by trying to run this adjusted code:

    PHP Code:
    mysql_select_db("phpbb2"$linkID) or die(mysql_error());

    $sql "SELECT user_id FROM phpbb_users WHERE username = '$username'";

    // trace the contents of $sql
    echo $sql "<br>";

    $resultID mysql_query($sql$linkID) or die(mysql_error());

    // End of query commands
    // Check Username

    $num_rows mysql_num_rows($resultID); 
    $row mysql_fetch_array($resultID); 

    echo 
    "<pre>";
    var_dump($row);
    echo 
    "</pre>";

    $user_id $row[0]; 

    echo 
    "<br>" $user_id
    This should show you what your query acutally consisted of. Also, all returned values from the query will be shown. Perhaps it's just a typo, but I could also think that you're expecting form variables to extracted automagically by the register_globals option. In modern versions of PHP, this feature is disabled by default. Maybe your provider did an upgrade and failed to inform you. In this case, you could try with

    $_POST["username"]

    to get the values of the form variable instead of just writing $username.

    Hope that helps.

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    okay, thanks but I found my problem after trying some more test.
    I had a file (mysql.inc) with $username and $password varable in it for the MySQL username and password, so I changed it's name and it works.. kinda..

    Now even if I don't put a password in it logs in.
    As you can see I'm trying to use a PHPBB database, and it should work, but it's not checking password.

    here's the code (same as before):

    PHP Code:
    <?php

    // MySQL User Login, Copyright 2002 Acorn Webs. All Rights Reserved.
    //
    // This Script is for Acorn Webs use ONLY!
    // Includes Acorn Webs Clients.

    // Include Files

    require("includes/mysql.inc");

    // End of Include Files
    // query commands

    mysql_select_db("phpbb2"$linkID) or die(mysql_error());
    $resultID mysql_query("SELECT user_id FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

    // End of query commands
    // Check Username

    $num_rows mysql_num_rows($resultID); 
    $row mysql_fetch_array($resultID); 
    $user_id $row[0]; 

    if (
    $user_id == "") {
        print 
    "We're sorry, your username does not appear to be in our database.";
    }
    else {
    // End ofCheck Username
    // query commands

        
    $resultID mysql_query("SELECT user_password FROM phpbb_users WHERE username = '$username'"$linkID) or die(mysql_error());

        
    $encryptedpassword md5($password);
        
        
    $row mysql_fetch_array($resultID); 
        
    $passwordfromdb $row[0];
    // End of query commands
    // Check Password

        
    if ($encryptedpassword !== $passwordfromdb) {
            print 
    "We're sorry, your password or username is incorrect.";
        }
        else {
            print 
    "login currect";
        }
    }

    // End of Check Password

    mysql_close($linkID);

    ?>
    *BTW, It's my server
    Last edited by EthanX; 07-26-2002 at 07:02 PM.

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yuo have 1 too many = signs... change:
    PHP Code:
    // Check Password

        
    if ($encryptedpassword !== $passwordfromdb) {
            print 
    "We're sorry, your password or username is incorrect.";
        }
        else {
            print 
    "login currect";
        }
    }

    // End of Check Password 
    To:
    PHP Code:
    // Check Password

        
    if ($encryptedpassword != $passwordfromdb) {
            print 
    "We're sorry, your password or username is incorrect.";
        }
        else {
            print 
    "login currect";
        }
    }

    // End of Check Password 

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmm so simple.... but.. wait.. didn't work
    still getting "We're sorry, your password or username is incorrect." and I know my password is currect.

    So what's the problem??

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh man.. I feel so stupid

    I put !== back, then I decided to check my form.. and I had the password feild wrong!... gosh
    Sorry to wast anyones time.. seems my code was fine all the way.. all but my stupid form.

    Thanks anyways.

  • #7
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm... ok, uh...

    I think the error is in the declaration of $passwordfromdb ...

    Try changing:
    PHP Code:
    $row mysql_fetch_array($resultID); 
        
    $passwordfromdb $row[0]; 
    To:
    PHP Code:
    $passwordfromdb mysql_fetch_array($resultID); 
    Hope that works

  • #8
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    /\ Read Previous post I made /\
    It's working now.. my code unchanged from my first post.
    It was my form. Sorry for the troble.

  • #9
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Lol.. I made my post about same time you made yours... and was no problem I enjoyed working around with it anyways... I am finally learning some MySQL stuff and more PHP

  • #10
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, MySQL isn't hard to learn. PHP is prety simple too.
    Thanks once again for you time messing with my junk codin
    If you ever need anything just ask.. (I might help )
    (I sell hosting )

  • #11
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW, !== is currect. !== (Noy Identical to) != (Not equal to)

  • #12
    Regular Coder
    Join Date
    Jul 2002
    Location
    U.S. (Wish Japan though)
    Posts
    141
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, ok thanks... I only learned C++, and in that you used !=...

  • #13
    New Coder
    Join Date
    Jul 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay, cool.. that's one of the langues I'll learn later.


  •  

    Posting Permissions

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