Registered people can't login.
Results 1 to 6 of 6

Thread: Registered people can't login.

Threaded View

  1. #1
    Silver surfer
    Join Date
    Nov 2007
    Posts
    89

    Registered people can't login.

    Several people are registered in the database and I can see their details in the table using phpmyadmin.
    Unfortunately, when trying to login, this message is displayed:

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\login\login.php on line 50

    Password/e-mail entered does not match our records.
    Perhaps you need to register, just click the Register button on the header menu

    Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\login\login.php on line 77

    The relevant section of the code for the login page is given below:

    PHP Code:
    <?php 
    // This section processes submissions from the login form
    // Check if the form has been submitted:
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        
    //connect to database
    try {
        require (
    'mysqli_connect.php');
        
    // Validate the email address
        
    if (!empty($_POST['email'])) {
            
    $e mysqli_real_escape_string($dbcon$_POST['email']);
        } else {
        
    $e FALSE;
            echo 
    '<p class="error">You forgot to enter your email address.</p>';
        }
        
    // Validate the password
        
    if (!empty($_POST['psword'])) {
                
    $p mysqli_real_escape_string($dbcon$_POST['psword']);
        } else {
        
    $p FALSE;
            echo 
    '<p class="error">You forgot to enter your password.</p>';
        }
        if (
    $e && $p){//if no problems
    // Retrieve the user_id, psword, first_name and user_level for that
    // email/password combination
    $q 'SELECT user_id, psword, fname, user_level FROM users WHERE email="$e"';
     
    // Run the query and assign it to the variable $result
    $result mysqli_query ($dbcon$q);
    // Count the number of rows that match the email/password combination
    //echo mysqli_num_rows($result);
    if (mysqli_num_rows($result) == 1) { [B]//line 50[/B]
    //if one database row (record) matches the input:-
    // Start the session, fetch the record and insert the 
    // values in an array 
    $row mysqli_fetch_array($resultMYSQLI_NUM);
    if (
    password_verify($p$row[1])) {
    session_start();                                    
    // Ensure that the user level is an integer. 
    $_SESSION['user_level'] = (int) $row[3];
    // Use a ternary operation to set the URL
    $url = ($_SESSION['user_level'] === 1) ? 'admin-page.php' :
     
    'members-page.php'
    header('Location: ' $url); 
    // Make the browser load either the members or the admin page
    } else { // No password match was made.
    echo '<p class="error">Password/e-mail entered does not match our records.';
    echo 
    '<br>Perhaps you need to register, just click the Register;
    echo button on the header menu</p>'
    ;
    }
    } else { 
    // No e-mail match was made.
    echo '<p class="error">Password/e-mail entered does not match our records.';
    echo 
    '<br>Perhaps you need to register, just click the Register ';
    echo 
    'button on the header menu</p>';
    }
    } else { 
    // If there was a problem.
    echo '<p class="error">Please try again.</p>';
    }
    mysqli_free_result($result);[B]//Line 77[/B]
    mysqli_close($dbcon);
    } catch(
    Exception $e)
    {
    print  
    "An Exception occurred. Message: " $e->getMessage();
    }
    catch(
    Error $e)
    {
    print  
    "An Error occurred. Message: " $e->getMessage();
    }    
    // no else to allow user to enter values
    ?>
    Last edited by Awestruck; 09-13-2017 at 07:54 AM. Reason: to highlight the the lines 50 and 777

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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