prepare("SELECT id FROM applications WHERE farmer_id = ? AND scheme_id = ?"); $stmt->execute([$farmer_id, $scheme_id]); $existing_application = $stmt->fetch(); if ($existing_application) { $_SESSION['message'] = [ 'type' => 'warning', 'text' => 'You have already applied for this scheme.' ]; } else { // Insert new application $stmt = $pdo->prepare("INSERT INTO applications (farmer_id, scheme_id) VALUES (?, ?)"); if ($stmt->execute([$farmer_id, $scheme_id])) { $_SESSION['message'] = [ 'type' => 'success', 'text' => 'You have successfully applied for the scheme!' ]; } else { $_SESSION['message'] = [ 'type' => 'danger', 'text' => 'There was an error processing your application. Please try again.' ]; } } // Redirect back to the scheme page header("Location: scheme.php?id=" . $scheme_id); exit(); ?>