<?php
require_once "../config/db.php";

if($_SERVER['REQUEST_METHOD'] !== 'POST'){
    die("Invalid request");
}

$title = trim($_POST['title'] ?? '');
$amount = (float) ($_POST['amount'] ?? 0);
$date = $_POST['expense_date'] ?? '';

if(empty($title) || !$amount || empty($date)){
    die("All fields required");
}

$stmt = $conn->prepare("
    INSERT INTO expenses (title, amount, expense_date)
    VALUES (?, ?, ?)
");

$stmt->bind_param("sds", $title, $amount, $date);
$stmt->execute();


header("Location: ../pages/add_expense.php?success=1");
exit;
