Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/projects/anton-quiz/logged-in/

dashboard.php
result.php
test.php

dashboard.php

65 lines UTF-8 Windows (CRLF)
<?php

session_start
();
if (!
$_SESSION["id"]) {
    
header('Location: ../index.php');
    die();
}

require_once 
__DIR__ '/../dbconnect.php';

?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard</title>
</head>

<body>
    <h1>Startsida</h1>

    <div>
        <h2>Tester du kan göra:</h2>
        <?php
        $one 
1;

        
$stmt $conn->prepare('SELECT * FROM quizdb_tests WHERE is_enabled = ?');
        
$stmt->bind_param("i"$one);
        
$stmt->execute();

        
$testsDbResult $stmt->get_result();

        foreach (
$testsDbResult as $tests) {
        
?>

            <a href="test.php?id=<?php echo $tests['id']; ?>"><?php echo $tests["test_name"?></a>

            <?php
            
// Kontrollera om användaren gjort ett test tidigare
            
$stmt $conn -> prepare('SELECT id FROM quizdb_results WHERE user_id = ? AND test_id = ?');
            
$stmt -> bind_param('ii'$_SESSION["id"], $tests["id"]);
            
$stmt -> execute();

            
$resultsDbResult =$stmt -> get_result();

            if (
mysqli_num_rows($resultsDbResult) > 0) {
                
?>
                <!-- Kolla user med session i result.php -->
                <a href="result.php?test_id=<?php echo $tests['id']?>">Resultat: <?php echo $tests["test_name"?></a><br>
                <?php
            
}
    
            
?>
        <?php
        
}
        
?>
    </div>

    <a href="../endpoints/log-out.php">Logga ut</a>
</body>

</html>