Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/submissions/projekt-quiz/

README.md
admin/
create_admin.php
create_quiz.php
css/
dashboard.php
debug_questions.php
includes/
index.php
leaderboard.php
login.php
logout.php
my_results.php
quiz.php
quiz_result.php
register.php
sqlcredentials

debug_questions.php

47 lines ASCII Windows (CRLF)
<?php
require 'includes/db_connect.php';

echo 
"<h2>Questions in Database</h2>";
echo 
"<table border='1' cellpadding='5'>";
echo 
"<tr><th>ID</th><th>Quiz ID</th><th>Question Order</th><th>Question Text</th></tr>";

$stmt $pdo->query("
    SELECT id, quiz_id, question_text, question_order 
    FROM questions 
    ORDER BY quiz_id DESC, question_order 
    LIMIT 20
"
);

while(
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo 
"<tr>";
    echo 
"<td>" $row['id'] . "</td>";
    echo 
"<td>" $row['quiz_id'] . "</td>";
    echo 
"<td>" $row['question_order'] . "</td>";
    echo 
"<td>" htmlspecialchars(substr($row['question_text'], 050)) . "</td>";
    echo 
"</tr>";
}
echo 
"</table>";

echo 
"<h2>Answers in Database (last 20)</h2>";
echo 
"<table border='1' cellpadding='5'>";
echo 
"<tr><th>ID</th><th>Question ID</th><th>Answer Order</th><th>Is Correct</th><th>Answer Text</th></tr>";

$stmt $pdo->query("
    SELECT id, question_id, answer_text, is_correct, answer_order 
    FROM answers 
    ORDER BY question_id DESC, answer_order 
    LIMIT 20
"
);

while(
$row $stmt->fetch(PDO::FETCH_ASSOC)) {
    echo 
"<tr>";
    echo 
"<td>" $row['id'] . "</td>";
    echo 
"<td>" $row['question_id'] . "</td>";
    echo 
"<td>" $row['answer_order'] . "</td>";
    echo 
"<td>" . ($row['is_correct'] ? 'YES' 'no') . "</td>";
    echo 
"<td>" htmlspecialchars(substr($row['answer_text'], 050)) . "</td>";
    echo 
"</tr>";
}
echo 
"</table>";
?>