Show sourcecode
The following files exists in this folder. Click to view.
admin.php
createQuiz.php
createadmin.php
logIn.php
myStats.php
playquiz.php
result.php
scoreboard.php
signIn.php
start.php
startsida.php
stats.php
style.css
tables.php
update.php
playquiz.php
72 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
<?php
/** @var PDO $dbconn */
include ("start.php");
?>
<!-- Svarsformulär som omdirigerar till en resultatsida -->
<form action="result.php" method="post">
<?php
try {
if (isset($_GET["quizId"])) {
$quizId = $_GET["quizId"];
// Sparar quizets id i ett dolt input-element
echo "<input type='hidden' name='quizId' value='$quizId'>";
// Välj quizet med det skickade id:t
$sql = "SELECT * FROM quizes WHERE id=?";
$stmt = $dbconn->prepare($sql);
$data = array($quizId);
$stmt->execute($data);
$quiz = $stmt->fetch(PDO::FETCH_ASSOC);
$quizname = $quiz["quizname"];
// Skriv ut quizets namn
echo "<h1>$quizname</h1>";
// Välj ut alla frågor som tillhör quizet
$sql = "SELECT * FROM questions WHERE quizId=?";
$questions = $dbconn->prepare($sql);
$data = array($quizId);
$questions->execute($data);
// Loopa igenom alla frågor
while ($q = $questions->fetch(PDO::FETCH_ASSOC)) {
$questionId = $q["id"];
$question = $q["question"];
// Skriv ut frågan
echo "<div id='q$questionId'><h2>$question</h2>";
// Välj ut alla svar till frågan
$sql = "SELECT * FROM answers WHERE questionId=?";
$answers = $dbconn->prepare($sql);
$data = array($questionId);
$answers->execute($data);
// Skriv ut alla svar
while ($a = $answers->fetch(PDO::FETCH_ASSOC)) {
$answerId = $a["id"];
$answer = $a["answer"];
echo "<input type='radio' id='a$answerId' name='a$questionId' value='a$answerId'>
<label for='a$answerId'>$answer</label><br>";
}
echo "</div>";
}
}
}
catch (PDOException $e) {
echo $e->getMessage() . "<br>";
}
?>
<input type="submit" value="Rätta">
</form>
</body>
</html>