prepare($sql); $stmt->execute([$customer_id, $plan_id, $amount, $status]); header("Location: invoices.php"); exit; } catch (PDOException $e) { $errors[] = "Database error: " . $e->getMessage(); } } } // Fetch customers and plans for dropdowns try { $pdo = db(); $customer_stmt = $pdo->query("SELECT id, name FROM customers ORDER BY name"); $customers = $customer_stmt->fetchAll(PDO::FETCH_ASSOC); $plan_stmt = $pdo->query("SELECT id, name FROM plans ORDER BY name"); $plans = $plan_stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { $customers = []; $plans = []; $errors[] = "Could not fetch data for form."; } ?>