📁 File Manager
🏠 /
/
home
/
u857492117
/
domains
/
mangaldaicollege.org
/
public_html
/
dk1
/
admin
Dosya Düzenle: edit_question.php
<?php session_start(); include("../config.php"); // Redirect if admin not logged in if(!isset($_SESSION['admin_id'])){ header("Location: admin_login.php"); exit; } $admin_name = $_SESSION['admin_name']; $error = ''; $success = ''; // Check question_id if(!isset($_GET['question_id'])){ die("Question ID not provided."); } $question_id = intval($_GET['question_id']); // Fetch question details $question_res = mysqli_query($conn, "SELECT * FROM question_bank WHERE question_id='$question_id'"); if(mysqli_num_rows($question_res) == 0){ die("Question not found."); } $question = mysqli_fetch_assoc($question_res); // Handle form submission if($_SERVER['REQUEST_METHOD'] == 'POST'){ $question_text = mysqli_real_escape_string($conn, $_POST['question_text']); $option_a = mysqli_real_escape_string($conn, $_POST['option_a']); $option_b = mysqli_real_escape_string($conn, $_POST['option_b']); $option_c = mysqli_real_escape_string($conn, $_POST['option_c']); $option_d = mysqli_real_escape_string($conn, $_POST['option_d']); $correct_answer = strtoupper($_POST['correct_answer']); $difficulty_level = $_POST['difficulty_level']; $marks = intval($_POST['marks']); if($question_text=='' || $option_a=='' || $option_b=='' || $option_c=='' || $option_d=='' || !in_array($correct_answer,['A','B','C','D'])){ $error = "Please fill all fields correctly."; } else { $update = mysqli_query($conn, " UPDATE question_bank SET question_text='$question_text', option_a='$option_a', option_b='$option_b', option_c='$option_c', option_d='$option_d', correct_answer='$correct_answer', difficulty_level='$difficulty_level', marks='$marks' WHERE question_id='$question_id' "); if($update){ $success = "Question updated successfully!"; $question = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM question_bank WHERE question_id='$question_id'")); } else { $error = "Database error: ".mysqli_error($conn); } } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Edit Question</title> <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet"> <style> body { font-family: 'Poppins', sans-serif; background: #f4f6f8; margin:0; } .navbar { background: linear-gradient(90deg,#6a11cb,#2575fc); color: white; padding: 15px 50px; display:flex; justify-content: space-between; align-items: center; } .navbar a { color:white; text-decoration: none; margin-left:20px; font-weight:600; } .navbar a:hover { text-decoration: underline; } .container { width: 700px; margin: 50px auto; background: #fff; padding: 30px; border-radius: 12px; box-shadow: 0 10px 20px rgba(0,0,0,0.15); } h2 { color: #6a11cb; text-align: center; margin-bottom: 20px; } form input, form textarea, form select { width: 100%; padding: 12px; margin: 10px 0; border-radius: 8px; border:1px solid #ccc; } form button { width: 100%; background: #2575fc; color:white; border:none; padding:12px; border-radius:8px; font-weight:600; cursor:pointer; transition:0.3s; } form button:hover { background: #6a11cb; } .message { text-align:center; margin-bottom:15px; font-weight:600; } .success { color: green; } .error { color: red; } </style> </head> <body> <div class="navbar"> <h1>Admin Panel</h1> <div> Welcome, <b><?php echo htmlspecialchars($admin_name); ?></b> | <a href="index.php">Dashboard</a> | <a href="admin_logout.php">Logout</a> </div> </div> <div class="container"> <h2>Edit Question</h2> <?php if($error) echo "<p class='message error'>$error</p>"; ?> <?php if($success) echo "<p class='message success'>$success</p>"; ?> <form method="post"> <textarea name="question_text" placeholder="Question Text" rows="3" required><?php echo htmlspecialchars($question['question_text']); ?></textarea> <input type="text" name="option_a" placeholder="Option A" value="<?php echo htmlspecialchars($question['option_a']); ?>" required> <input type="text" name="option_b" placeholder="Option B" value="<?php echo htmlspecialchars($question['option_b']); ?>" required> <input type="text" name="option_c" placeholder="Option C" value="<?php echo htmlspecialchars($question['option_c']); ?>" required> <input type="text" name="option_d" placeholder="Option D" value="<?php echo htmlspecialchars($question['option_d']); ?>" required> <input type="text" name="correct_answer" placeholder="Correct Answer (A/B/C/D)" value="<?php echo $question['correct_answer']; ?>" maxlength="1" required> <select name="difficulty_level" required> <option value="easy" <?php if($question['difficulty_level']=='easy') echo 'selected'; ?>>Easy</option> <option value="medium" <?php if($question['difficulty_level']=='medium') echo 'selected'; ?>>Medium</option> <option value="hard" <?php if($question['difficulty_level']=='hard') echo 'selected'; ?>>Hard</option> </select> <input type="number" name="marks" placeholder="Marks" value="<?php echo $question['marks']; ?>" min="1" required> <button type="submit">Update Question</button> </form> </div> </body> </html>
💾 Kaydet
İptal