prepare("SELECT * FROM user_services WHERE user_id = ? AND service_id = ? AND status = 'active'"); $stmt->execute([$user_id, $service_id]); if ($stmt->rowCount() > 0) { $message = "You are already subscribed to this service."; } else { // Add the subscription $stmt = $pdo->prepare("INSERT INTO user_services (user_id, service_id) VALUES (?, ?)"); $stmt->execute([$user_id, $service_id]); $message = "You have successfully subscribed to the service!"; } } catch (PDOException $e) { $message = "An error occurred: " . $e->getMessage(); } } else { header('Location: dashboard.php'); exit; } ?>