<?php include 'db.php'; ?>

<!DOCTYPE html>
<html lang="en">
    <link rel="stylesheet" href="style.css">
<head>
    <meta charset="UTF-8">
    <title>Banner Manager</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>

<h2>Add New Banner</h2>
<h2 style="color: #ff00000 font-size: 24px; font-weight: bold; text-align: center; margin: 20px 0;">
    Note:- Please upload banners like b1.png , b2.png ....
</h2>
<form action="add_banner.php" method="POST" enctype="multipart/form-data">
    Title: <input type="text" name="title" required><br>
    Name: <input type="text" name="name" required><br>
    Banner URL: <input type="file" name="banner" required><br>
    <button type="submit">Add Banner</button>
</form>

<h3>All Banners</h3>

<?php
$result = $conn->query("SELECT * FROM banners");
while ($row = $result->fetch_assoc()) {
    echo "<div>";
    echo "<img src='uploads/" . $row['image'] . "' width='200'><br>";
    echo "Title: " . $row['title'] . "<br>";
    echo "Name: " . $row['name'] . "<br>";
    echo "<form action='update_banner.php' method='POST' enctype='multipart/form-data'>";
    echo "<input type='hidden' name='id' value='{$row['id']}'>";
    echo "New Title: <input type='text' name='title' value='{$row['title']}'><br>";
    echo "New Name: <input type='text' name='name' value='{$row['name']}'><br>";
    echo "New Banner: <input type='file' name='banner'><br>";
    echo "<button type='submit'>Update</button>";
    echo "</form>";
    echo "<form action='delete_banner.php' method='POST'>";
    echo "<input type='hidden' name='id' value='{$row['id']}'>";
    echo "<button type='submit'>Delete</button>";
    echo "</form>";
    echo "</div><hr>";
}
?>

</body>
</html>
