$choice_id) { $stmt = db()->prepare("SELECT is_correct FROM choices WHERE id = ? AND question_id = ?"); $stmt->execute([$choice_id, $question_id]); $choice = $stmt->fetch(); if ($choice && $choice['is_correct']) { $correct_answers++; } } // Calculate score $score = ($total_questions > 0) ? ($correct_answers / $total_questions) * 100 : 0; // Save the result to the database $insert_stmt = db()->prepare("INSERT INTO exam_results (exam_id, user_id, score) VALUES (?, ?, ?)"); $insert_stmt->execute([$exam_id, $user_id, $score]); // Fetch exam details for display $exam_stmt = db()->prepare("SELECT title FROM exams WHERE id = ?"); $exam_stmt->execute([$exam_id]); $exam = $exam_stmt->fetch(); $page_title = "Hasil Ujian"; ?>
Anda menjawab dari pertanyaan dengan benar.