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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Login system help.

    So, when my user goes to log in, i'm pondering how i check that his username entered and password entered matches that in the db.

    Heres what i wrote:

    PHP Code:
    $query "SELECT * FROM Members WHERE loginName='$username' AND password='$password'";
    $resultmysql_query($query);
    $check =mysql_num_rows($result);



    if(
    $check 0) {
    echo 
    "Error: Username or password did not match! Please try again!"
    }else{
    echo 
    "Successfully Logged in"
    But that returns this error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fantasy/public_html/loginprocess.php on line 15

    Any help ?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Your query probably failed. Echo the $query var and see if username and password are set

  • #3
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the if isn't closed off either, but you should have gotten an error from that.

    Changing

    if($check < 0) to if($check <= 0) might help

    how can the query return less than 0?


    also try this

    $query = mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
    $check =mysql_num_rows($query);
    Last edited by Forsaken; 03-17-2007 at 08:37 PM.

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    They are set

  • #5
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    PHP Code:
    $query mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
    $check =mysql_num_rows($query);


    if(
    $check <= 0) {
    echo 
    "Error: Username or password did not match! Please try again!"
    }else{ 
    Returns
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/fantasy/public_html/loginprocess.php on line 14
    Error: Username or password did not match! Please try again!

    Even though, when i echo the query it contains the right password and username

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Something's not right then.

    Make sure your db field names are right. Make sure the info in the db is exactly how it is in your query. Are you connecting to the db? Is it the right db?

  • #7
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    $query = mysql_query("SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password'");
    $check =mysql_num_rows($query);
    
    
    echo(" SELECT * FROM `Members` WHERE `loginName` = '$username' AND `password` = '$password' ");
    it should display SELECT * FROM `Members` Where .....

    copy and paste that into your phpmyadmin sql, it should tell you whats wrong from there.

  • #8
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    i ran mysql_error(); and it said that my table doesn't exist x.x;

    When i go to check in phpmyadmin it is there in front of my eyes, and only 10 seconds ago i had matched up results from that table.

    I seriously believe my server i'm on could be messed up, unless it is my coding.

  • #9
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I doub't it, maybe you have member, but not Member, and its possible you might have members or even Members and your not noticing the small mistake

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Have you called it Members, or members? It's case sensitive

  • #11
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Yeah, you guys were right xD

    Now, new errors to do with the next part of the script.

    PHP Code:
    if($check <= 0) {
    echo 
    "Error: Username or password did not match! Please try again!"
    }else{
    echo 
    "Successfully Logged in";
    session_register("username"$username);
    session_register("password"$password);
    echo 
    "<br><br>Welcome, "$username ." please go back to the <a href='main.php'>main page</a>";
    }

    ?> 
    Now i'm getting a few errors:

    Successfully Logged in
    Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/fantasy/public_html/functions.php:14) in /home/fantasy/public_html/loginprocess.php on line 22


    Welcome, Ice please go back to the main page
    Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

  • #12
    New Coder
    Join Date
    May 2006
    Location
    California
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would do

    $_SESSION['username'] = $username; etc...


    heres a link:
    http://us3.php.net/session_register
    Last edited by Forsaken; 03-17-2007 at 09:14 PM.

  • #13
    Regular Coder
    Join Date
    Jan 2007
    Posts
    217
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Works like a treat now! Thanks both of you for your help!

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by ole90 View Post
    Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/fantasy/public_html/functions.php:14) in /home/fantasy/public_html/loginprocess.php on line 22
    You have to set the session variable before you output anything.

  • #15
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Quote Originally Posted by Inigoesdr View Post
    You have to set the session variable before you output anything.
    That's not quite right. You can set session variables anywhere, but you cannot start a session (session_start()) anywhere. session_start() has to be before anything is outputted


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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