<?php
include 'db.php';

$id = $_POST['id'];
$title = $_POST['title'];
$name = $_POST['name'];

if (!empty($_FILES['banner']['name'])) {
    $target_dir = "uploads/";
    $image_name = basename($_FILES["banner"]["name"]);
    $target_file = $target_dir . $image_name;
    move_uploaded_file($_FILES["banner"]["tmp_name"], $target_file);

    $sql = "UPDATE banners SET title='$title', name='$name', image='$image_name' WHERE id=$id";
} else {
    $sql = "UPDATE banners SET title='$title', name='$name' WHERE id=$id";
}

if ($conn->query($sql)) {
    echo "Banner updated successfully!";
} else {
    echo "Error: " . $conn->error;
}

header("Location: index.php");
?>
