Results 1 to 3 of 3

Thread: Login Boolean error

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default Login Boolean error

    Hello everyone,

    Somewhere on this page it is giving this error


    ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\messaging2\Login2.php on line 18
    Call Stack
    # Time Memory Function Location
    1 0.0004 375824 {main}( ) ..\Login2.php:0
    2 0.0052 383328 mysql_num_rows ( ) ..\Login2.php:18

    ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Documents and Settings\Owner\Desktop\canberra amatuer productions\www\Canberra Amatuer Productions\messaging2\Login2.php on line 25
    Call Stack
    # Time Memory Function Location
    1 0.0004 375824 {main}( ) ..\Login2.php:0
    2 0.0055 383496 mysql_num_rows ( ) ..\Login2.php:25



    PHP Code:
    <?php 
    session_start
    ();
    require_once 
    'database.php';

        
    $username $_POST['user'];
        
    $escaped_username mysql_real_escape_string($username);
        
    $md5_password md5($_POST['pass']);
        
        
    $queryN mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND 
    level='1'"
    );#This variable will check if the user is a level 1 user (Normal User)
        
    $queryA mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND 
    level='9'"
    );#This variable will check if the user is a level 9 user (Admin User)
        
                
        
    if(mysql_num_rows($queryN) == 1)
        {
            
    $resultN mysql_fetch_assoc($queryN);                     
    $_SESSION['user'] = $_POST['user'];    
    header("location:Index.php");      
    }

    elseif(
    mysql_num_rows($queryA) == 1)
        {
            
    $resultA mysql_fetch_assoc($queryA);                     
    $_SESSION['admin'] = $_POST['user'];    
    header("location:index.php");      
    }

    else{
    echo 
    "Wrong Username or Password";
    }
    ?>
    <form name="back" method="post" action="login.php">
    <input type="submit" name="back" id="back" value="Back to Home">
    Any help?
    Last edited by keyboard; 08-12-2011 at 08:59 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    I'm almost positive that you have some SQL syntax error that is causing all of your queries to return false.

    Try adding or die(mysql_error()) at the end of your mysql_query() functions. That will return MySQL errors if they occur. Then we can diagnose the problem.

    Example:
    PHP Code:
      
        $queryN 
    mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND 
    level='1'"
    ) or die(mysql_error());#This variable will check if the user is a level 1 user (Normal User)
        
    $queryA mysql_query("select * from user where username = '".$username."' and password = '".$md5_password."' AND 
    level='9'"
    ) or die(mysql_error());#This variable will check if the user is a level 9 user (Admin User) 
    Btw, you've already had a very similar error here:
    http://www.dynamicdrive.com/forums/s...d.php?p=257873

    mysql_query() always returns a boolean result of false when query errors occur.
    - Josh

  3. #3
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    And I gave the same advice as before and it eventually led to you solving your problem.
    - Josh

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
  •