OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
quiz
/
adminProcess
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
05/19/2025 10:07:16 AM
rwxr-xr-x
📄
updateQuestion.php
3.64 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
updateQuiz.php
3.57 KB
05/19/2025 10:07:16 AM
rw-r--r--
Editing: updateQuestion.php
Close
<? require_once('../assets/php/validate.logged.php'); require_once('../assets/php/db_config.php'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (($_POST['act']) == "update") { $quizId = isset($_POST['quizId']) ? $_POST['quizId'] : null; $queId = isset($_POST['queId']) ? $_POST['queId'] : null; $ques = isset($_POST['que']) ? $_POST['que'] : null; $option1 = isset($_POST['option1']) ? $_POST['option1'] : null; $option2 = isset($_POST['option2']) ? $_POST['option2'] : null; $option3 = isset($_POST['option3']) ? $_POST['option3'] : null; $option4 = isset($_POST['option4']) ? $_POST['option4'] : null; $answer = isset($_POST['answer']) ? $_POST['answer'] : null; // Validate input if (empty($queId) || !is_numeric($queId)) { echo json_encode(['success' => false, 'message' => 'Invalid Ques ID']); exit; } // SQL Query $sql = "UPDATE questions SET question=?,option1=?, option2=?, option3=?, option4=?, answer=? WHERE id=?"; // Prepare the statement $stmt = $conn->prepare($sql); // Bind the parameters $stmt->bind_param("ssssssi", $ques,$option1, $option2, $option3, $option4, $answer, $queId); // Execute the statement if ($stmt->execute()) { // Success echo json_encode(['success' => true, 'message' => 'Quiz Details updated successfully']); } else { // Error handling echo json_encode(['success' => false, 'message' => 'Error: ' . $stmt->error]); } // Close the statement and connection $stmt->close(); } elseif (($_POST['act']) == "new") { $quizId = isset($_POST['quizId']) ? $_POST['quizId'] : null; $ques = isset($_POST['ques']) ? $_POST['ques'] : null; $option1 = isset($_POST['option1']) ? $_POST['option1'] : null; $option2 = isset($_POST['option2']) ? $_POST['option2'] : null; $option3 = isset($_POST['option3']) ? $_POST['option3'] : null; $option4 = isset($_POST['option4']) ? $_POST['option4'] : null; $answer = isset($_POST['answer']) ? $_POST['answer'] : null; // SQL Query $sql = "INSERT INTO questions (quiz_id,question, option1, option2,option3,option4, answer) VALUES (?,?,?,?, ?, ?, ?)"; // Prepare the statement $stmt = $conn->prepare($sql); // Bind the parameters $stmt->bind_param("issssss", $quizId, $ques,$option1, $option2, $option3, $option4,$answer); // Execute the statement if ($stmt->execute()) { // Success echo json_encode(['success' => true, 'message' => 'Question Details updated successfully']); } else { // Error handling echo json_encode(['success' => false, 'message' => 'Error: ' . $stmt->error]); } // Close the statement and connection $stmt->close(); } elseif (($_POST['act']) == "delete") { $queId = $_POST['id']; // Prepare the SQL DELETE query $sql = "DELETE FROM questions WHERE id = ?"; // Prepare the statement $stmt = $conn->prepare($sql); // Bind the parameter (quizId) $stmt->bind_param("i", $queId); // Execute the DELETE statement if ($stmt->execute()) { echo "success"; // Return success message if deletion is successful } else { echo "error"; // Return error message if something goes wrong } // Close the statement $stmt->close(); } }