query("SELECT * FROM destinations WHERE id=$id")->fetch_assoc(); if (!$dest) { header("Location: destinations.php"); exit; } $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $country_code = strtoupper(trim($_POST['country_code'] ?? '')); $description = trim($_POST['description'] ?? ''); $show_home = isset($_POST['show_home']) ? 1 : 0; if (empty($name)) { $error = 'Destination name is required.'; } else { // Handle image upload $image_filename = $dest['image'] ?? ''; // keep existing by default if (!empty($_FILES['image']['name'])) { $allowed = ['jpg','jpeg','png','webp','gif']; $ext = strtolower(pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)); if (!in_array($ext, $allowed)) { $error = 'Invalid image type. Allowed: jpg, jpeg, png, webp, gif'; } elseif ($_FILES['image']['size'] > 5 * 1024 * 1024) { $error = 'Image must be under 5 MB.'; } else { $new_filename = 'dest_' . time() . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $_FILES['image']['name']); $upload_path = '../uploads/' . $new_filename; if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) { // Delete old image if it was an upload (not a static asset) if (!empty($dest['image']) && file_exists('../uploads/' . $dest['image'])) { unlink('../uploads/' . $dest['image']); } $image_filename = $new_filename; } else { $error = 'Failed to upload new image.'; } } } if (empty($error)) { // Try full update first (with optional columns) $stmt = $conn->prepare("UPDATE destinations SET name=?, country_code=?, description=?, image=?, show_home=? WHERE id=?"); if ($stmt) { $stmt->bind_param("ssssii", $name, $country_code, $description, $image_filename, $show_home, $id); if ($stmt->execute()) { header("Location: destinations.php?msg=saved"); exit; } else { $error = 'Database error: ' . $stmt->error; } } else { // Fallback: basic update $stmt2 = $conn->prepare("UPDATE destinations SET name=?, image=? WHERE id=?"); if ($stmt2) { $stmt2->bind_param("ssi", $name, $image_filename, $id); if ($stmt2->execute()) { header("Location: destinations.php?msg=saved"); exit; } else { $error = 'Database error: ' . $stmt2->error; } } else { $error = 'Prepare error: ' . $conn->error; } } } } } // Build current image thumbnail $thumb = ''; $dest_imgs_static = [ 'India' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.03.52 (1).jpeg', 'Dubai' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.06.04.jpeg', 'Egypt' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.08.25.jpeg', 'China' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.10.08.jpeg', 'Vietnam' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.10.15.jpeg', 'Thailand' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.12.15.jpeg', 'Singapore' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.10.46.jpeg', 'Azerbaijan' => '../assets/destinations img/WhatsApp Image 2026-05-08 at 15.13.35.jpeg', ]; if (!empty($dest['image']) && file_exists('../uploads/' . $dest['image'])) { $thumb = '../uploads/' . htmlspecialchars($dest['image']); } elseif (isset($dest_imgs_static[$dest['name']])) { $thumb = $dest_imgs_static[$dest['name']]; } ?> Edit Destination | Methsisila Admin
Edit Destination

Editing:

Back to List
Destination Details
style="width:40px;height:22px;">
Destination Image

Current image:

Click or drag to replace image

JPG, PNG, WEBP up to 5 MB