prepare("INSERT INTO gallery (title, category, image) VALUES (?, ?, ?)"); $stmt->execute([$title, $category, $image]); $msg = "
Image added to gallery.
"; } catch(Exception $e) { $msg = "
Error adding image.
"; } } // Delete Gallery Image if (isset($_GET['delete'])) { $id = $_GET['delete']; try { $stmt = $pdo->prepare("DELETE FROM gallery WHERE id = ?"); $stmt->execute([$id]); $msg = "
Image deleted successfully.
"; } catch(Exception $e) { $msg = "
Error deleting image.
"; } } // Fetch Gallery try { $stmt = $pdo->query("SELECT * FROM gallery ORDER BY id DESC"); $gallery = $stmt->fetchAll(); } catch (PDOException $e) { if ($e->getCode() == '42S02') { $pdo->exec("CREATE TABLE IF NOT EXISTS `gallery` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(150) NOT NULL, `category` varchar(100) NOT NULL, `image` varchar(255) NOT NULL, `is_active` tinyint(1) NOT NULL DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4"); $stmt = $pdo->query("SELECT * FROM gallery ORDER BY id DESC"); $gallery = $stmt->fetchAll(); } else { $msg = "
Database Error: " . htmlspecialchars($e->getMessage()) . "
"; $gallery = []; } } ?>

Manage Gallery

Image Title Category Status Action
img No image Active Inactive