0
In a login system, I take the e-mail and password given by the user by a form and see if there is any identical information in the database.
$conn = new mysqli("localhost", "root", "", "prisma");
$result = $conn->query("SELECT * FROM tb_users ORDER BY iduser");
$data = array();
$x = -1;
while($row=$result->fetch_array(MYSQLI_ASSOC)){
array_push($data, $row);
$x += 1;
if($user == $data[$x]["desusername"] && $pass == $data[$x]["despassword"]){
if($user == $adms){
$_SESSION['isAdmin'] = true;
header('Location: index.php');
}
else{
header('Location: index.php');
}
}
else{
echo "Erro. Insira seus dados corretamente!";
echo $data[$x]["desusername"];
echo $data[$x]["despassword"];
echo $user;
echo $pass;
break;
}
}
$user being the email given by the user, $pass the password given by the user, $data[$x]["desusername"] the database users and $data[$x]["despassword"] the found passwords;
However, when logging in, the $data[$x]["desusername"] and $data[$x]["despassword"] are the first item in my database, and there is one more item to go through!
Ex. The first item is "[email protected]", and password "123". The second is "[email protected]" and password "321";
If the user enters the second item in the form, my while will only have taken the first item to compare in the if.