Update navigation links to point to employee-login.php and enhance login error handling

This commit is contained in:
vista-man
2025-04-10 17:13:49 +02:00
parent d5779156d2
commit c7300a2b0a
12 changed files with 168 additions and 74 deletions

View File

@@ -14,27 +14,36 @@ if ($conn->connect_error) {
}
// Retrieve form data
$username = $_POST['username'];
$password = $_POST['password'];
$username = isset($_POST['username']) ? trim(htmlspecialchars($_POST['username'])) : '';
$password = isset($_POST['password']) ? trim(htmlspecialchars($_POST['password'])) : '';
// Validate credentials
$sql = "SELECT id, password_hash FROM employees WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($user_id, $password_hash);
$stmt->fetch();
if ($password_hash && password_verify($password, $password_hash)) {
// Start session and store user ID
session_start();
$_SESSION['user_id'] = $user_id;
echo "Login successful!";
header("Location: ../qr/qr.html"); // Redirect to QR scanner page
if ($stmt) {
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($user_id, $password_hash);
$stmt->fetch();
} else {
echo "Invalid login credentials.";
header("Location: ../employee-login.html?error=server_error");
exit();
}
$stmt->close();
$conn->close();
try {
if ($password_hash && password_verify($password, $password_hash)) {
// Start session and store user ID
session_start();
$_SESSION['user_id'] = $user_id;
header("Location: ../qr/qr.html"); // Redirect to QR scanner page
exit();
} else {
// Redirect back to login page with an error message
header("Location: ../employee-login.html?error=invalid_credentials");
exit();
}
} finally {
$stmt->close();
$conn->close();
}
?>