Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require 'database.php';
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
if (isset($_GET['list_id'])) {
$list_id = $_GET['list_id'];
// Fetch the list data
$stmt = $pdo->prepare("SELECT * FROM lists WHERE id = ?");
$stmt->execute([$list_id]);
$list = $stmt->fetch(PDO::FETCH_ASSOC);
if ($list) {
// Decode questions and answers for display
$questions = json_decode($list['questions']);
$answers = json_decode($list['answers']);
} else {
echo "List not found.";
exit;
}
} else {
echo "No list specified.";
exit;
}
// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_GET['list_id'])) {
$name = $_POST['name'];
$mode = $_POST['mode'];
$questions = json_encode($_POST['questions']);
$answers = json_encode($_POST['answers']);
// Update the list in the database
$stmt = $pdo->prepare("UPDATE lists SET name = ?, mode = ?, questions = ?, answers = ? WHERE id = ?");
$stmt->execute([$name, $mode, $questions, $answers, $list_id]);
// Redirect back to the dashboard
header("Location: dashboard.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit List</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="list-container">
<h2>Bewerk Quiz</h2>
<form action="editList.php?list_id=<?php echo $list_id; ?>" method="post">
<label for="name">Quiz Naam:</label>
<input type="text" id="name" name="name" value="<?php echo htmlspecialchars($list['name']); ?>">
<label for="mode">Mode:</label>
<select id="mode" name="mode">
<option value="PrivΓ©" <?php if ($list['mode'] == 'PrivΓ©') echo 'selected'; ?>>PrivΓ©</option>
<option value="Openbaar" <?php if ($list['mode'] == 'Openbaar') echo 'selected'; ?>>Openbaar</option>
</select>
<?php for ($i = 0; $i < 3; $i++): ?>
<label for="question<?php echo $i; ?>">Vraag <?php echo ($i + 1); ?>:</label>
<input type="text" id="question<?php echo $i; ?>" name="questions[]" value="<?php echo htmlspecialchars($questions[$i] ?? ''); ?>">
<label for="answer<?php echo $i; ?>">Antwoord <?php echo ($i + 1); ?>:</label>
<input type="text" id="answer<?php echo $i; ?>" name="answers[]" value="<?php echo htmlspecialchars($answers[$i] ?? ''); ?>">
<?php endfor; ?>
<button type="submit" name="save">Opslaan</button>
</form>
</div>
</body>
</html>