Пример #1
0
<?php

require_once "../includes/sessions.php";
require_once "../includes/db-connection.php";
require_once "../includes/functions.php";
?>

<?php 
$quiz = get_quiz_by_id($_GET["quiz_id"]);
if (!$quiz) {
    // Quiz id was missing or invalid or
    // could not be found in the database.
    $_SESSION["error_message"] = "Failed to delete quiz. Quiz does not exist.";
    redirect_to("manage-quizzes.php");
}
$id = $quiz["quiz_id"];
$quiz_name = $quiz["quiz_name"];
$query = "DELETE FROM quiz WHERE quiz_id = {$id} LIMIT 1";
$result = mysqli_query($db, $query);
if ($result && mysqli_affected_rows($db) == 1) {
    $query2 = "DELETE FROM quiz_has_question WHERE quiz_id = {$id}";
    $result2 = mysqli_query($db, $query2);
    if ($result2) {
        // Success
        $_SESSION["message"] = "Successfully deleted quiz: {$quiz_name}.";
        redirect_to("manage-quizzes.php");
    }
} else {
    // Failure
    redirect_to("manage-quizzes.php");
}
Пример #2
0
<?php 
$page = "edit-quiz.php";
?>

<?php 
include '../includes/layouts/header.php';
?>





<?php 
// If quiz does not exist, redirect back to Manage Quizzes Page
$id = isset($_GET["quiz_id"]) ? $_GET["quiz_id"] : "";
$quiz = get_quiz_by_id($id);
if (!$quiz) {
    redirect_to("manage-quizzes.php");
}
?>

<?php 
if (isset($_POST['submit-edit-quiz'])) {
    // The Edit Quiz Form was submitted
    // Validate Edit Quiz Form inputs
    $fields_with_max_lengths = array("quiz_name" => 255, "category" => 255, "attempts" => 11);
    foreach ($fields_with_max_lengths as $field => $max) {
        $value = trim($_POST[$field]);
        if (!value_within_range($value, 1, $max)) {
            $error_messages[$field] = ucfirst($field) . " is too long.";
        }