prepare("SELECT * FROM surveys WHERE id = ?"); $survey_stmt->execute([$survey_id]); $survey = $survey_stmt->fetch(); if (!$survey) { header('Location: surveys.php'); exit; } // Handle form submission for new question if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['question_text'])) { $question_text = trim($_POST['question_text']); $question_type = trim($_POST['question_type']); $options = ($question_type === 'multiple-choice') ? trim($_POST['options']) : null; if (!empty($question_text) && !empty($question_type)) { $stmt = db()->prepare("INSERT INTO survey_questions (survey_id, question_text, question_type, options) VALUES (?, ?, ?, ?)"); $stmt->execute([$survey_id, $question_text, $question_type, $options]); header("Location: manage_questions.php?survey_id=" . $survey_id); exit; } } // Handle question deletion if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_question'])) { $question_id = $_POST['delete_question']; $stmt = db()->prepare("DELETE FROM survey_questions WHERE id = ? AND survey_id = ?"); $stmt->execute([$question_id, $survey_id]); header("Location: manage_questions.php?survey_id=" . $survey_id); exit; } // Fetch all questions for the survey $questions_stmt = db()->prepare("SELECT * FROM survey_questions WHERE survey_id = ? ORDER BY created_at ASC"); $questions_stmt->execute([$survey_id]); $questions = $questions_stmt->fetchAll(); $pageTitle = "Manage Questions for " . htmlspecialchars($survey['title']); require_once 'templates/header.php'; ?>

Manage Questions for ""

Back to Surveys

Add New Question

Existing Questions

No questions added to this survey yet.

Type:
Options: