Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projekt/quiz/

account.php
admin_register.php
create_quiz.php
create_tables.php
index.php
login.php
nav.css
nav.php
quiz.php
quiz_select.php
register.php
result_details.php
result_simple.php
submit_create_quiz.php
submit_quiz.php

create_quiz.php

61 lines UTF-8 Windows (CRLF)
<?php
session_start
();
if (!isset(
$_SESSION['user_id'])) {
    
header("Location: login.php");
    exit;
}
include(
'../../incl/dbconnect.php');

$user_id $_SESSION['user_id'];
// Kontrollera att användaren är administratör
$stmt $dbconn->prepare("SELECT is_admin FROM users_quiz WHERE id = ?");
$stmt->execute([$user_id]);
$is_admin $stmt->fetchColumn();
if (!
$is_admin) {
    echo 
"Åtkomst nekad. Du är inte administratör.";
    exit;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <title>Skapa Quiz</title>
    <link rel="stylesheet" href="nav.css">
</head>
<body>
    <?php include 'nav.php'?>
    
    <h1>Skapa nytt quiz</h1>
    <form action="submit_create_quiz.php" method="post">
        <h2>Testinformation</h2>
        <label for="titel">Titel:</label>
        <input type="text" name="titel" id="titel" required><br>
        
        <label for="beskrivning">Beskrivning:</label>
        <textarea name="beskrivning" id="beskrivning" rows="4" cols="50"></textarea><br>
        
        <h2>Frågor och svar</h2>
        <?php for ($i 1$i <= 5$i++): ?>
            <fieldset>
                <legend>Fråga <?php echo $i?></legend>
                <label for="fraga_<?php echo $i?>">Fråga:</label>
                <input type="text" name="fraga_text[<?php echo $i?>]" id="fraga_<?php echo $i?>" required><br>
                
                <p>Svarsalternativ:</p>
                <?php for ($j 1$j <= 3$j++): ?>
                    <label for="svar_<?php echo $i.'_'.$j?>">
                        <input type="radio" name="korrekt[<?php echo $i?>]" value="<?php echo $j?>" required>
                        Rätt svar?
                    </label>
                    <input type="text" name="svar_text[<?php echo $i?>][<?php echo $j?>]" id="svar_<?php echo $i.'_'.$j?>" required><br>
                <?php endfor; ?>
            </fieldset>
            <br>
        <?php endfor; ?>
        
        <input type="submit" value="Skapa Quiz">
    </form>
</body>
</html>