mercredi 26 décembre 2018

How do i convince the code that the data i am trying to pull out of a MySQL database actually exists?

I am testing a login code and i ran into a problem where the information collected from a MySQL database can not be found even though the information exists inside the table, the code below says that there is 0 rows with the information i am trying to pull out, therefore it fails to execute it's primary function and always ends up executing the else solution

I have been googling around and tried different combinations and ways the code can be written as it is '".$username."' instead of '$username' but nothing seems to be working except in case where equal it to zero but that way it looses it's purpose and executes the primary function no matter what

$sql = "SELECT * FROM users WHERE username = '$username' AND pass = '$password' ";

$result = mysqli_query($mysqli,$sql);

if (mysqli_num_rows($result)>0){
    echo "Login Success!";
    exit();
}
else{
    echo "Login Failed";
    exit();
}

I expected to solve this problem on my own but i got totally confused and don't even know what i have tried so far and what else is there to be tried

Aucun commentaire:

Enregistrer un commentaire