<?php 

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="fraud_audit.csv"');

$output = fopen("php://output", "w");

fputcsv($output, ['Txn ID', 'Amount', 'Country', 'Risk Score', 'Risk Level', 'Date']);

$sql = "SELECT id, amount, to_country, risk_score, risk_level, created_at 
        FROM transactions 
        WHERE is_flagged = 1";

$result = $conn->query($sql);

while ($row = $result->fetch_assoc()) {
    fputcsv($output, $row);
}

fclose($output);
exit;


?>