prepare("INSERT INTO bunks (name, owner, contact, location) VALUES (?, ?, ?, ?)"); $stmt->execute([$name, $owner, $contact, $location]); $_SESSION['notification'] = ['text' => 'Bunk added successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error adding bunk: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'Bunk name is required.', 'type' => 'warning']; } } // Edit Bunk elseif (isset($_POST['edit_bunk'])) { $id = $_POST['bunk_id']; $name = trim($_POST['name']); $owner = trim($_POST['owner']); $contact = trim($_POST['contact']); $location = trim($_POST['location']); if (!empty($name) && !empty($id)) { try { $stmt = $db->prepare("UPDATE bunks SET name = ?, owner = ?, contact = ?, location = ? WHERE id = ?"); $stmt->execute([$name, $owner, $contact, $location, $id]); $_SESSION['notification'] = ['text' => 'Bunk updated successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error updating bunk: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'Bunk name and ID are required.', 'type' => 'warning']; } } header("Location: bunks.php"); exit; } // Delete Bunk if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { try { $db = db(); $stmt = $db->prepare("DELETE FROM bunks WHERE id = ?"); $stmt->execute([$_GET['id']]); $_SESSION['notification'] = ['text' => 'Bunk deleted successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error deleting bunk: ' . $e->getMessage(), 'type' => 'danger']; } header("Location: bunks.php"); exit; } if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; unset($_SESSION['notification']); } try { $db = db(); $stmt = $db->query("SELECT id, name, owner, contact, location, created_at FROM bunks ORDER BY created_at DESC"); $bunks = $stmt->fetchAll(); } catch (PDOException $e) { $bunks = []; $notification = ['text' => 'Error fetching bunks: ' . $e->getMessage(), 'type' => 'danger']; } ?> Bunk Management

Bunk Management

Name Owner Contact Location Created Actions
No bunks found. Add one to get started!