I'm starting to see the prepared statement of SQL . I have the following code for a simple login
:
$stmt = $mysqli->prepare("SELECT id_admin,usuario,hash_pass FROM admins WHERE usuario = ?");
$stmt->bind_param("s", $usuario);
$stmt->execute();
$stmt->bind_result($id, $usuario, $hash_pass);
while ($stmt->fetch()) /* obtener los valores */
{
if(password_verify($password, $hash_pass)){
$_SESSION['usuario'] = $usuario;
$_SESSION['id'] = $id;
header('location: admin-area.php');
die();
}
else{
$resultado = "Datos incorrectos.";
}
}
$stmt->free_result(); /* Libera la memoria de los resultados */
$stmt->close(); /* Cerrar la sentencia */
$mysqli->close(); /* Cerrar la conexion. */
The variable that happened in bind_param()
is $ user , has the same name as the variable that happened in bind_result()
. I tried it and there is no problem. Could this be the same or could there be some error in more complex sentences? Should the variables have different names?