prepare("SELECT * FROM users WHERE username = :username"); $stmt->execute(['username' => $username]); $user = $stmt->fetch(); if ($user && password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['user_name'] = $user['name']; $_SESSION['user_role'] = $user['role']; header('Location: ../dashboard.php'); exit; } else { $_SESSION['error'] = 'Usuario o contraseƱa incorrectos.'; header('Location: ../index.php'); exit; } } catch (PDOException $e) { $_SESSION['error'] = 'Error del sistema. Contacte al administrador.'; header('Location: ../index.php'); exit; } } else { header('Location: ../index.php'); exit; } ?>