I want to make a login with a previous record, so looking for me I found some tutorials, and this is the code to login:
<?php
session_start();
?>
<?php
$host_db = "localhost";
$user_db = "root";
$pass_db = "123";
$db_name = "proyecto_pre";
$tbl_name = "usuario";
$conexion = new mysqli($host_db, $user_db, $pass_db, $db_name);
if ($conexion->connect_error) {
die("La conexion falló: " . $conexion->connect_error);
}
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT * FROM $tbl_name WHERE user = '$username'" ;
$result = $conexion->query($sql);
if ($result->num_rows === 1) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (password_verify($password, $row['password'])) {
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (5 * 60);
echo "Bienvenido! " . $_SESSION['username'];
echo "<br><br><a href=panel-control.php>Panel de Control</a>";
} else {
echo "Username o Password estan incorrectos.";
echo "<br><a href='login.php'>Volver a Intentarlo</a>";
}
}
mysqli_close($conexion)
?>
However, when entering the username and password of my database, the code will send me the message "Username or Password are incorrect." , and when a user enters and incorrect pass the checklogin.php file (the login code) is shown in white.
Does anyone know what the error is? I'm new to php.