<?php
require 'koneksi.php';

$tgl = date('Y-m-d');
$nik = $_POST['nik'];
$isi = $_POST['isi_laporan'];
$ft  = $_FILES['foto']['name'];
$file = $_FILES['foto']['tmp_name'];
$st = 0;

// Simpan foto ke folder 'foto'
$target = "foto/" . basename($ft);
move_uploaded_file($file, $target);

// Query insert data
$sql = "INSERT INTO pengaduan (tgl_pengaduan, nik, isi_laporan, foto, status) 
        VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssi", $tgl, $nik, $isi, $ft, $st);

if ($stmt->execute()) {
    echo "<script>
        alert('Data berhasil disimpan, Terimakasih sudah menulis laporan');
        window.location='masyarakat.php';
    </script>";
} else {
    echo "<script>
        alert('Gagal menyimpan data!');
        window.location='masyarakat.php';
    </script>";
}

$stmt->close();
$conn->close();
?>
