<?php
include "../koneksi.php";

$judul   = $_POST['judul'];
$isi     = $_POST['isi'];
$tanggal = $_POST['tanggal'];

$foto = $_FILES['foto']['name'];
$tmp  = $_FILES['foto']['tmp_name'];

$namaFoto = time() . "_" . $foto;
$folder = "../uploads/berita/";

move_uploaded_file($tmp, $folder . $namaFoto);

$query = mysqli_query($conn, "
    INSERT INTO berita (judul, isi, tanggal, foto)
    VALUES ('$judul', '$isi', '$tanggal', '$namaFoto')
");

if (!$query) {
    die("GAGAL SIMPAN: " . mysqli_error($conn));
}

header("Location: berita.php");
exit;
