   <?php
    // ডাটাবেজ কানেকশন সেটআপ
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "school_monir_final";

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    // ফরম ডাটা প্রসেস করা
    if (isset($_POST['submit'])) {
        $type = $_POST['type'];
        $description = $_POST['description'];
        $date = $_POST['date'];
        $amount = $_POST['amount'];

        // আয় হলে ক্রেডিট, ব্যয় হলে ডেবিট
        $credit = $type === "আয়" ? $amount : 0;
        $debit = $type === "ব্যয়" ? $amount : 0;

        // ব্যালেন্স হিসাব
        $balance = $credit - $debit;

        // ডাটাবেজে ডাটা ইনসার্ট করা
        $sql = "INSERT INTO transactions (date, description, credit, debit, balance) 
                VALUES ('$date', '$description', '$credit', '$debit', '$balance')";

        if ($conn->query($sql) === TRUE) {
            header("Location: http://localhost/schoolfinal/accounts.php");
        } else {
            header("Location: http://localhost/schoolfinal/accounts.php");
        }
    }

    // কানেকশন বন্ধ করা
    $conn->close();
    ?>