prepare("INSERT INTO services (title, description, image) VALUES (?, ?, ?)"); $stmt->execute([$title, $description, $image]); $msg = "
Service added successfully.
"; } catch(Exception $e) { $msg = "
Error adding service.
"; } } // Edit Service if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']) && $_POST['action'] == 'edit') { $id = $_POST['id']; $title = $_POST['title']; $description = $_POST['description']; $is_active = isset($_POST['is_active']) ? 1 : 0; // File upload logic $image_query_part = ""; $params = [$title, $description, $is_active]; if (!empty($_FILES['image']['name'])) { $upload_dir = '../uploads/services/'; if(!is_dir($upload_dir)) @mkdir($upload_dir, 0777, true); $image = time() . '_' . basename($_FILES['image']['name']); if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_dir . $image)) { $image_query_part = ", image = ?"; $params[] = $image; } } $params[] = $id; try { $stmt = $pdo->prepare("UPDATE services SET title = ?, description = ?, is_active = ? $image_query_part WHERE id = ?"); $stmt->execute($params); $msg = "
Service updated successfully.
"; } catch(Exception $e) { $msg = "
Error updating service.
"; } } // Delete Service if (isset($_GET['delete'])) { $id = $_GET['delete']; try { $stmt = $pdo->prepare("DELETE FROM services WHERE id = ?"); $stmt->execute([$id]); $msg = "
Service deleted successfully.
"; } catch(Exception $e) { $msg = "
Error deleting service.
"; } } // Fetch Services try { $stmt = $pdo->query("SELECT * FROM services ORDER BY id DESC"); $services = $stmt->fetchAll(); } catch (PDOException $e) { if ($e->getCode() == '42S02') { $pdo->exec("CREATE TABLE IF NOT EXISTS `services` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(150) NOT NULL, `description` text 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"); // Insert default services data $pdo->exec("INSERT INTO `services` (`title`, `description`, `image`, `is_active`) VALUES ('Aluminium Pantry Cupboard', 'Premium quality, rust-proof aluminium pantry cupboards customized to fit your kitchen space perfectly with modern luxury finishes.', 'pantry.jpg', 1), ('TV Wall Design', 'Modern TV wall units incorporating LED lighting, floating shelves, and high-end materials to elevate your living room.', 'tv-wall.jpg', 1), ('Wall Decoration', 'Aesthetic and durable wall decorations using advanced cladding and interior materials.', 'wall-deco.jpg', 1), ('Clothing Wardrobe', 'Spacious, elegantly designed aluminium and glass wardrobes tailored for maximum storage and style.', 'wardrobe.jpg', 1), ('Partition Decoration Wall', 'Stylish glass and aluminium partition walls to divide spaces while maintaining an open, modern feel.', 'partition.jpg', 1), ('Granite Works', 'High-quality granite countertops and fittings for kitchens, bathrooms, and commercial spaces.', 'granite.jpg', 1), ('Island Table', 'Custom-built kitchen island tables providing extra workspace and a contemporary focal point for your kitchen.', 'island-table.jpg', 1), ('Bar Counter', 'Luxurious bar counters for home or commercial use, designed with premium finishes and ambient lighting.', 'bar-counter.jpg', 1), ('Dressing Table', 'Modern dressing tables featuring elegant mirrors, built-in lighting, and sleek storage solutions.', 'dressing-table.jpg', 1)"); $stmt = $pdo->query("SELECT * FROM services ORDER BY id DESC"); $services = $stmt->fetchAll(); } else { $msg = "
Database Error: " . htmlspecialchars($e->getMessage()) . "
"; $services = []; } } ?>

Manage Services

ID Image Title Description Status Action
img No image ... Active Inactive