<?php
require_once __DIR__ . '/../includes/db.php';
$pdo = db();

if (isset($_POST['tombol_tes'])) {
    $t = $_POST['thn'];
    $j = $_POST['jdl'];
    $d = $_POST['dsc'];

    // Query super maksa
    $q = $pdo->prepare("INSERT INTO histori (tahun, judul, deskripsi) VALUES (?, ?, ?)");
    if ($q->execute([$t, $j, $d])) {
        echo "<h1 style='color:green'>BERHASIL MASUK DATABASE!</h1>";
        echo "<a href='index.php'>Cek Beranda</a>";
    } else {
        echo "<h1 style='color:red'>GAGAL TOTAL!</h1>";
        print_r($q->errorInfo());
    }
    exit;
}
?>

<form method="POST">
    Tahun: <input type="number" name="thn" required><br>
    Judul: <input type="text" name="jdl" required><br>
    Desc: <textarea name="dsc" required></textarea><br>
    <button type="submit" name="tombol_tes">KLIK UNTUK TES SIMPAN</button>
</form>