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

quiz_select.php

51 lines UTF-8 Windows (CRLF)
<?php
session_start
();

// Kontrollera om användaren är inloggad annars omdirigera till login
if (!isset($_SESSION['user_id'])) {
    
header("Location: login.php");
    exit;
}

include (
'../../incl/dbconnect.php');

try {
    
// Hämta alla tillgängliga tester från databasen
    
$stmt $dbconn->query("SELECT * FROM testinfo_quiz");
    
$tests $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch(
PDOException $e) {
    echo 
"Fel vid hämtning av tester: " $e->getMessage();
    exit;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
    <meta charset="UTF-8">
    <title>Välj Quiz</title>
    <link rel="stylesheet" href="nav.css">

</head>
<body>
<?php include ('nav.php'); ?>

    <h2>Välj ett frågetest</h2>
    <?php if (!empty($tests)) : ?>
        <ul>
            <?php foreach ($tests as $test) : ?>
                <li>
                    <a href="quiz.php?test_id=<?php echo $test['id']; ?>">
                        <?php echo htmlspecialchars($test['titel']); ?>
                    </a>
                    <?php if (!empty($test['beskrivning'])) : ?>
                        - <?php echo htmlspecialchars($test['beskrivning']); ?>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
    <?php else : ?>
        <p>Inga tester hittades</p>
    <?php endif; ?>
</body>
</html>