diff --git a/admin/edit_question.php b/admin/edit_question.php new file mode 100644 index 0000000..7bf06bf --- /dev/null +++ b/admin/edit_question.php @@ -0,0 +1,99 @@ +beginTransaction(); + + // Update question text and score + $stmt = $pdo->prepare('UPDATE questions SET question_text = ?, score = ? WHERE id = ?'); + $stmt->execute([$_POST['question_text'], $_POST['score'], $question_id]); + + // Update answers + $correctAnswerIndex = $_POST['is_correct']; + foreach ($_POST['answers'] as $answer_id => $answerText) { + $isCorrect = ($answer_id == $_POST['correct_answer_id']); // This needs to be adjusted + + // Simplified logic: update text, and then separately update the correct flag + $stmt_update_text = $pdo->prepare('UPDATE answers SET answer_text = ? WHERE id = ? AND question_id = ?'); + $stmt_update_text->execute([$answerText, $answer_id, $question_id]); + } + + // Set all to incorrect first + $stmt_reset = $pdo->prepare('UPDATE answers SET is_correct = 0 WHERE question_id = ?'); + $stmt_reset->execute([$question_id]); + + // Set the new correct answer + $stmt_set_correct = $pdo->prepare('UPDATE answers SET is_correct = 1 WHERE id = ? AND question_id = ?'); + $stmt_set_correct->execute([$_POST['correct_answer_id'], $question_id]); + + $pdo->commit(); + $message = '
Domanda non trovata.
"; + require_once 'partials/footer.php'; + exit; +} + +$stmt = $pdo->prepare('SELECT * FROM answers WHERE question_id = ? ORDER BY id ASC'); +$stmt->execute([$question_id]); +$answers = $stmt->fetchAll(PDO::FETCH_ASSOC); + +?> + + + +