query($sql); if ($result->num_rows == 0) { redirect(SITE_URL . ADMIN_PATH . '/manage-surveys.php'); } $survey = $result->fetch_assoc(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $title = clean_input($_POST['title']); $website_link = clean_input($_POST['website_link']); $description = clean_input($_POST['description']); $support_contact = clean_input($_POST['support_contact']); // Validation if (empty($title) || empty($website_link) || empty($description) || empty($support_contact)) { $error = "All fields are required"; } else { $new_filename = $survey['image']; // Check if new image is uploaded if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) { $allowed_types = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']; $file_type = $_FILES['image']['type']; if (!in_array($file_type, $allowed_types)) { $error = "Only JPG, PNG, and GIF images are allowed"; } else { $file_extension = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $new_filename = uniqid() . '.' . $file_extension; $upload_path = '../uploads/' . $new_filename; if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_path)) { // Delete old image if (file_exists('../uploads/' . $survey['image'])) { unlink('../uploads/' . $survey['image']); } } else { $error = "Failed to upload new image"; } } } if (empty($error)) { // Update survey site $sql = "UPDATE survey_sites SET title = '$title', website_link = '$website_link', description = '$description', support_contact = '$support_contact', image = '$new_filename' WHERE id = $survey_id"; if ($conn->query($sql)) { $success = "Survey site updated successfully!"; // Refresh survey data $result = $conn->query("SELECT * FROM survey_sites WHERE id = $survey_id"); $survey = $result->fetch_assoc(); } else { $error = "Failed to update survey site: " . $conn->error; } } } } $page_title = 'Edit Survey Site'; include '../includes/header.php'; ?>
← Back to Survey Sites

Edit Survey Site

Current Image
Leave empty to keep current image