Jump to content
Larry Ullman's Book Forums

Recommended Posts

what is the difference between your sql call and my sql call:

        // $q = "SELECT user_id, first_name FROM users WHERE $userid AND pass=SHA2('$p', 512)";
        $q = "SELECT user_id, first_name, username FROM users WHERE username='$uname' AND pass=SHA2('$p', 512)";
        $r = @mysqli_query($dbc, $q); // Run the query.
        
        // Check the result:
        if (mysqli_num_rows($r) == 1) {
            echo 'check_login == 1';
            // Fetch the record:
            $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
            
            // Return true and the record:
            return [true, $row];
            
        } else { // Not a match!        //  'The email address and password entered do not match those on file.';
            $errors[] = 'The user name and password entered do not match those on file.';
        }

it does not return anything, it just stays in index.php calling login screen over and over!? It does not enters the "if" statement.  Thank you

Link to comment
Share on other sites

The differences between the two queries are pretty obvious but what's really important is:

  1. What's the users table definition look like?
  2. What error message, if any, is MySQL returning. 

The answer to the first might inform the second, but you ought to just look at the MySQL error directly. That's assuming there is an error. If there is no error then your query is syntactically fine, there's just no matching rows. 

Link to comment
Share on other sites

I do get the right results when I enter the query in workbench.  I found that when I call login screen and enter “correct values” and execute, it clears the fields and stays at the login screen BUT when I enter “incorrect values" it executes properly and displays errors that those values are incorrect!?  After a day of messing with that I finally checked the script and it was from the earlier chapter. It works now. Thanks

Link to comment
Share on other sites

 Share

×
×
  • Create New...