query("SELECT * FROM packages WHERE id = $id")->fetch_assoc(); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $title = sanitize($conn, $_POST['title']); $country_id = (int)$_POST['country_id']; $tour_name = sanitize($conn, $_POST['tour_name']); $duration = sanitize($conn, $_POST['duration']); $travel_period = sanitize($conn, $_POST['travel_period']); $price = (float)$_POST['price']; $landmarks = sanitize($conn, $_POST['landmarks']); $includes = sanitize($conn, $_POST['includes']); $sort_order = isset($_POST['sort_order']) ? (int)$_POST['sort_order'] : 0; $tour_type = isset($_POST['tour_type']) && in_array($_POST['tour_type'], ['group', 'private']) ? $_POST['tour_type'] : 'group'; $update_fields = [ "title = '$title'", "country_id = $country_id", "tour_name = '$tour_name'", "duration = '$duration'", "travel_period = '$travel_period'", "price = $price", "landmarks = '$landmarks'", "includes = '$includes'", "sort_order = $sort_order", "tour_type = '$tour_type'" ]; if (!empty($_FILES['main_image']['name'])) { $main_image = time() . '_' . $_FILES['main_image']['name']; move_uploaded_file($_FILES['main_image']['tmp_name'], "../uploads/" . $main_image); $update_fields[] = "main_image = '$main_image'"; } if (!empty($_FILES['brochure_pdf']['name'])) { $brochure_pdf = time() . '_' . $_FILES['brochure_pdf']['name']; move_uploaded_file($_FILES['brochure_pdf']['tmp_name'], "../uploads/" . $brochure_pdf); $update_fields[] = "brochure_pdf = '$brochure_pdf'"; } $sql = "UPDATE packages SET " . implode(', ', $update_fields) . " WHERE id = $id"; if ($conn->query($sql)) { if (!empty($_FILES['gallery']['name'][0])) { foreach ($_FILES['gallery']['tmp_name'] as $key => $tmp_name) { $img_name = time() . '_' . $_FILES['gallery']['name'][$key]; move_uploaded_file($tmp_name, "../uploads/" . $img_name); $conn->query("INSERT INTO package_gallery (package_id, image) VALUES ($id, '$img_name')"); } } echo ""; } } ?>