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

$judul = mysqli_real_escape_string($conn, $_POST['judul']);
$deskripsi = mysqli_real_escape_string($conn, $_POST['deskripsi']);
$tanggal = $_POST['tanggal'];

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

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

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

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

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

header("Location: dashboard.php");
