prepare("SELECT id, password, role FROM users WHERE username = ? LIMIT 1"); $stmt->bind_param("s", $username); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $user = $result->fetch_assoc(); if (password_verify($password, $user['password'])) { $_SESSION['user_id'] = $user['id']; $_SESSION['role'] = $user['role']; // Redirect based on role if ($user['role'] == 'store') { header("Location: http://localhost/compadre_inventory/store/dashboard.php"); } elseif ($user['role'] == 'bodega') { header("Location: http://localhost/compadre_inventory/bodega/dashboard.php"); } elseif ($user['role'] == 'admin') { header("Location: http://localhost/compadre_inventory/admin/dashboard.php"); } else { $error = "Invalid role."; } exit(); } else { $error = "Invalid password."; } } else { $error = "Username not found."; } } } ?>