prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$userId]); $user = $stmt->fetch(); // Handle form submission if ($_SERVER['REQUEST_METHOD'] === 'POST') { $medicineName = trim($_POST['medicine_name']); $quantity = filter_input(INPUT_POST, 'quantity', FILTER_VALIDATE_INT); $description = trim($_POST['description']); if (!empty($medicineName) && $quantity > 0) { $sql = "INSERT INTO pooled_requests (user_id, medicine_name, status, participants) VALUES (?, ?, 'Pending', 1)"; $stmt = $pdo->prepare($sql); if ($stmt->execute([$userId, $medicineName])) { header("Location: pooled-requests.php?success=1"); exit; } else { $error = "Failed to create pool. Please try again."; } } else { $error = "Medicine name and a valid quantity are required."; } } ?>