OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
quiz
/
assets
/
process
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/15/2025 11:20:33 AM
rwxr-xr-x
📄
quiz_submit.php
1.28 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
quiz_submit_test.php
3 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
temp_answer.php
2.07 KB
05/19/2025 10:07:16 AM
rw-r--r--
Editing: temp_answer.php
Close
<?php include('../php/db_config.php'); include('../php/validate.logged.php'); if ($_SERVER['REQUEST_METHOD'] === 'POST') { $questionId = intval($_POST['question_id']); $quizId = intval($_POST['quiz_id']); $selectedOption = $_POST['selected_option']; try { // Check if the record exists $checkQuery = "SELECT id FROM temp_answer WHERE que_id = ? AND user_id = ? AND quiz_id = ?"; $checkStmt = $conn->prepare($checkQuery); $checkStmt->bind_param('iii', $questionId, $gUserId, $quizId); $checkStmt->execute(); $checkResult = $checkStmt->get_result(); if ($checkResult->num_rows > 0) { // If the record exists, update the answer $updateQuery = "UPDATE temp_answer SET answer = ? WHERE que_id = ? AND user_id = ? AND quiz_id = ?"; $updateStmt = $conn->prepare($updateQuery); $updateStmt->bind_param('siii', $selectedOption, $questionId, $gUserId, $quizId); if ($updateStmt->execute()) { echo json_encode(['status' => 'success', 'message' => 'Answer updated successfully!']); } else { throw new Exception('Failed to update the answer.'); } } else { // If the record does not exist, insert a new one $insertQuery = "INSERT INTO temp_answer (que_id, user_id, quiz_id, answer) VALUES (?, ?, ?, ?)"; $insertStmt = $conn->prepare($insertQuery); $insertStmt->bind_param('iiis', $questionId, $gUserId, $quizId, $selectedOption); if ($insertStmt->execute()) { echo json_encode(['status' => 'success', 'message' => 'Answer saved successfully!']); } else { throw new Exception('Failed to save the answer.'); } } } catch (Exception $e) { error_log($e->getMessage()); echo json_encode(['status' => 'error', 'message' => $e->getMessage()]); } } else { echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']); } ?>