exec("CREATE TABLE IF NOT EXISTS `hero_images` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(200) DEFAULT '', `subtitle` varchar(500) DEFAULT '', `image` varchar(255) NOT NULL, `sort_order` int(11) DEFAULT 0, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); } catch(Exception $e) {} // Toggle active if (isset($_GET['toggle'])) { $id = (int)$_GET['toggle']; try { $pdo->prepare("UPDATE hero_images SET is_active = 1 - is_active WHERE id=?")->execute([$id]); $msg = "
Hero image status toggled.
"; } catch(Exception $e) {} } // Delete if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; try { $stmt = $pdo->prepare("SELECT image FROM hero_images WHERE id=?"); $stmt->execute([$id]); $row = $stmt->fetch(); if ($row) @unlink($upload_dir . $row['image']); $pdo->prepare("DELETE FROM hero_images WHERE id=?")->execute([$id]); $msg = "
Hero image deleted.
"; } catch(Exception $e) { $msg = "
Error deleting image.
"; } } // Add hero image if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'add') { $title = $_POST['title']; $subtitle = $_POST['subtitle']; $sort_order = (int)$_POST['sort_order']; $fname = ''; if (!empty($_FILES['image']['name']) && $_FILES['image']['error'] == 0) { $fname = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', basename($_FILES['image']['name'])); move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir . $fname); } if ($fname) { try { $pdo->prepare("INSERT INTO hero_images (title, subtitle, image, sort_order) VALUES (?,?,?,?)") ->execute([$title, $subtitle, $fname, $sort_order]); $msg = "
Hero image added successfully!
"; } catch(Exception $e) { $msg = "
Error: " . e($e->getMessage()) . "
"; } } else { $msg = "
Please select an image to upload.
"; } } // Edit hero image if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'edit') { $id = (int)$_POST['id']; $title = $_POST['title']; $subtitle = $_POST['subtitle']; $sort_order = (int)$_POST['sort_order']; try { $fname = ''; if (!empty($_FILES['image']['name']) && $_FILES['image']['error'] == 0) { // Remove old image $old = $pdo->prepare("SELECT image FROM hero_images WHERE id=?"); $old->execute([$id]); $oldRow = $old->fetch(); if ($oldRow) @unlink($upload_dir . $oldRow['image']); $fname = time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', basename($_FILES['image']['name'])); move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir . $fname); $pdo->prepare("UPDATE hero_images SET title=?, subtitle=?, image=?, sort_order=? WHERE id=?") ->execute([$title, $subtitle, $fname, $sort_order, $id]); } else { $pdo->prepare("UPDATE hero_images SET title=?, subtitle=?, sort_order=? WHERE id=?") ->execute([$title, $subtitle, $sort_order, $id]); } $msg = "
Hero image updated!
"; } catch(Exception $e) { $msg = "
Error updating.
"; } } // Fetch all hero images $heroes = []; try { $stmt = $pdo->query("SELECT * FROM hero_images ORDER BY sort_order ASC, created_at DESC"); $heroes = $stmt->fetchAll(); } catch(Exception $e) {} ?>

Hero Section Images

These images appear as the background slideshow on the homepage hero section. Active images show on the website; inactive ones are hidden. Use Sort Order to control display sequence.

No hero images added yet. Click Add Hero Image to upload your first slide.

Hero
Order:
No title' ?>

No subtitle' ?>