<?php
require_once('connection.php');

$keterangan = $_GET['keterangan'] ?? '';  // Change from $_POST to $_GET

if ($keterangan) {
    // Query to insert data into tblSaran
    $sql = "INSERT INTO tblSaran (keterangan) VALUES (?)";

    if ($stmt = $con->prepare($sql)) {
        $stmt->bind_param("s", $keterangan); // Corrected to "s" for one string

        if ($stmt->execute()) {
            $response = [
                'success' => true,
                'message' => 'Data berhasil disimpan.'
            ];
        } else {
            $response = [
                'success' => false,
                'message' => 'Gagal menyimpan data.'
            ];
        }

        $stmt->close();
    } else {
        $response = [
            'success' => false,
            'message' => 'Gagal mempersiapkan pernyataan SQL.'
        ];
    }
} else {
    $response = [
        'success' => false,
        'message' => 'Keterangan wajib diisi.'
    ];
}

// Return response in JSON format
header('Content-Type: application/json');
echo json_encode($response);

// Close database connection
$con->close();
?>
