V1rus Private
User / IP
:
216.73.217.108
Host / Server
:
190.92.174.125 / aerosofthealthcare.com
System
:
Linux s3739.bom1.stableserver.net 4.18.0-513.24.1.lve.2.el8.x86_64 #1 SMP Fri May 24 12:42:50 UTC 2024 x86_64
Cmd
|
Upload
|
Mass Deface
|
Create
|
Sym
:
/
home
/
aerosoft
/
www
/
exam
/
Viewing: submit_exam.php
<?php include 'config.php'; if (!isset($_SESSION['student_id'])) { die(json_encode(['success' => false, 'message' => 'Unauthorized'])); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $exam_id = $_POST['exam_id']; $answers = $_POST['answers']; // Verify exam belongs to student $stmt = $pdo->prepare("SELECT * FROM exams WHERE id = ? AND student_id = ?"); $stmt->execute([$exam_id, $_SESSION['student_id']]); $exam = $stmt->fetch(); if (!$exam) { die(json_encode(['success' => false, 'message' => 'Invalid exam'])); } // Calculate score $score = 0; $total_questions = count($answers); foreach ($answers as $question_id => $selected_option) { $stmt = $pdo->prepare("SELECT correct_option FROM questions WHERE id = ?"); $stmt->execute([$question_id]); $question = $stmt->fetch(); if ($question && $question['correct_option'] == $selected_option) { $score++; } } $percentage = ($score / $total_questions) * 100; $status = $percentage >= 70 ? 'passed' : 'failed'; // Update exam $stmt = $pdo->prepare("UPDATE exams SET score = ?, total_marks = ?, percentage = ?, status = ?, completed_at = NOW() WHERE id = ?"); $stmt->execute([$score, $total_questions, $percentage, $status, $exam_id]); // Generate certificate if passed if ($status == 'passed') { $certificate_code = 'CERT-' . strtoupper(uniqid()); $expiry_date = date('Y-m-d', strtotime('+1 year')); $stmt = $pdo->prepare("INSERT INTO certificates (student_id, exam_id, certificate_code, expiry_date) VALUES (?, ?, ?, ?)"); $stmt->execute([$_SESSION['student_id'], $exam_id, $certificate_code, $expiry_date]); } echo json_encode([ 'success' => true, 'score' => $percentage, 'status' => $status ]); } ?>
Coded With 💗 by
HanzOFC