Related Posts

25 Comments

  1. Hey, for anyone following this tutorial, if you get the "Invalid user name or password" error when the password and user name are correct
    I found the issue for me.

    Some suggest disabling the encryption and this works, but the problem is your SQL database

    Back in tutorial 1 or 2 where you are creating your database, you select the size of the fields.
    My password field was 16 characters long
    HOWEVER
    the md5 string it creates is MORE than 16 characters. So in the sql database i noticed the the md5 password was being chopped so this would return an invalid password.
    once i made the password field accept around 40 characters, it worked fine.

    There are ways around this and checks you can do, but for the sake of this tutorial, this is the issue I found 🙂

  2. public function getDataByUsername($username) {
    $query = "SELECT * FROM users WHERE username = ?";
    $stmt = $this->con->prepare($query);

    $stmt->bind_param("s",$username);
    $stmt->execute(); //missing this in the video

    return $stmt->get_result()->fetch_assoc();

    }

    public function userLogin($username,$pass) {
    $query = "SELECT id FROM users WHERE username = ? AND password = ?" ;
    $stmt = $this->con->prepare($query);

    $password = md5($pass); //missing this in the video

    $stmt->bind_param("ss",$username, $password);
    $stmt->execute();
    $stmt->store_result();

    return $stmt->num_rows > 0 ;

    }

  3. Sir… Do you have tutorial for userLoggedIn and it will get the data according to their userId, like
    userTable – id, userId, username, password
    userInfor – userId, name, address

  4. Fatal error: Uncaught Error: Class 'DbOperations' not found in C:xampphtdocsapifunctionuserLogin.php:9 Stack trace: #0 {main} thrown in C:xampphtdocsapifunctionuserLogin.php on line 9

  5. I already use the datatype of the column as text or use $password = password_hash($pass,PASSWORD_DEFAULT); but i still got error like {"error":true,"message":"Invalid username or password"} how to solve this? Please help me

  6. [SOLUTION]
    FOR INVALID USERNAME OR LOGIN EVEN WITH CORRECT CREDENTIALS

    If you are getting the error "invalid login or password" even if the credentials are right, remove the encode to base64 ($password = md5($pass);) and change all $pass on all .php to %password.

    It worked for me.

  7. For those who having trouble with the method get_result() and couldnt install driver to your server , you can replace the get_result to this

    $stmt->execute();
    $stmt->bind_result($id,$username,$password,$email);
    while($stmt->fetch()){
    $res['id'] = $id;
    $res['username'] = $username;
    $res['password'] = $password;
    $res['email'] = $email;
    }

    return $res;

    p/s : make sure you create $res array in the beginning of the php file

  8. I'm facing problem when I try to run the userLogin.php in postman ,
    it shows the message like
    "Fatal error: Call to undefined method mysqli_stmt::get_result() in DbOperation.php "
    I check the code 3 to 4 time and code is same as provided , please solve this problem!!!!

  9. hi sir thanks for the great tutorial. i just have a little issue when i run the login script in chrome or any other browser it does not give me an error but it only display this to squared brackets []. how do i solve this please.?

  10. Hi sir….In the postman im getting like {"error":true,"message":"Invalid username and password"}. the username and password are same as in my database..so please help me to solve this problem…

  11. Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/u157139941/public_html/Android/includes/DbOperations.php on line:48
    line no:48 contain the method return $stmt->get_result()->fetch_assoc();

    whats the bug..?

  12. I got error in POSTMAN :
    Fatal error: Call to a member function bind_param() on boolean in C:xampphtdocsAndroid1includesDbOperations.php on line 28

    in DbOperations on line 28 is …
    $stmt = $this->con->prepare("SELECT id FROM users WHERE username = ? OR email = ?"); – line27
    $stmt->bind_param("ss",$username,$email); -line28
    $stmt->execute(); -line29

  13. i keep on getting {"error":true,"message":"Invalid username or password"} in the postman. the username and password are already the same as in my db. what should i do

Leave a Reply

Your email address will not be published.

© 2022 Code As Pro - Theme by WPEnjoy · Powered by WordPress