I was having an issue with my login.php because I was not being able to show the successfully-connected page after you log in, in a Debian virtual machine. I didn't know why it was happening because trying the same code/DB with XAMPP in Windows it was working perfectly. This is the code:
<?php
$error='';
if(isset($_POST['send'])){
$user=$_POST['user'];
$password=$_POST['password'];
$conexion = mysqli_connect("localhost", "root", "");
$db = mysqli_select_db($conexion, "aragonnature");
$consulta = mysqli_query($conexion, "SELECT * FROM usuarios WHERE user='$user' AND password='$password'");
$filas = mysqli_num_rows($consulta);
if($filas == 1){
header("Location: administracion.php");
} else {
$error = "Usuario o contraseña incorrecto.";
}
}
?>
TL;DR A friend helped me to solve it, turns out that I'm using PHP 8 and MySQL 7.4, so after executing the following code the problem was solved:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'yourpassword';
However I can't find nowhere why by doing this the problem was solved, can any of you please explain me? I'm new with this and want to learn as much as possible.
Regards!