prepare("SELECT * FROM surveys WHERE id = ?"); $survey_stmt->execute([$survey_id]); $survey = $survey_stmt->fetch(); if (!$survey) { $error_message = "The requested survey could not be found."; } else { // Fetch questions and their options $questions_stmt = $pdo->prepare("SELECT * FROM questions WHERE survey_id = ? ORDER BY id ASC"); $questions_stmt->execute([$survey_id]); $questions = $questions_stmt->fetchAll(); } } catch (PDOException $e) { $error_message = "A database error occurred."; // In a real app, you would log the detailed error: error_log($e->getMessage()); } } ?> <?php echo $survey ? htmlspecialchars($survey['title']) : 'Survey'; ?> - FormFlex Pro

$question): ?>
"; } elseif ($q_type == 'textarea') { echo ""; } elseif (in_array($q_type, ['radio', 'checkbox', 'select'])) { $options_stmt = $pdo->prepare("SELECT * FROM question_options WHERE question_id = ? ORDER BY id ASC"); $options_stmt->execute([$q_id]); $options = $options_stmt->fetchAll(); if ($q_type == 'select') { echo ""; } else { // radio or checkbox $input_type = $q_type; $name_attr = ($q_type == 'checkbox') ? $input_name . "[]" : $input_name; foreach ($options as $opt_index => $option) { $option_id = "q{$q_id}_opt{$opt_index}"; echo "
"; echo ""; echo ""; echo "
"; } } } ?>