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
tables.php
136 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
<?php
/** @var PDO $dbconn */
include ("start.php");
// if ($_COOKIE["type"] != "admin") {
// header("location: startsida.php");
// }
// Om en table har valts att raderas, ta bort den
if (isset($_POST["table"])) {
try {
$sql = "DROP TABLE IF EXISTS " . $_POST["table"];
$dbconn->exec($sql);
echo "Table deleted successfully";
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
} elseif (isset($_POST["create"])) {
// Körs om tabellerna ska skapas
try {
// Skapa Quizes
$sql = "CREATE TABLE quizes (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
quizname VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br>";
try {
// Skapa Questions
$sql = "CREATE TABLE questions (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
question VARCHAR(64) NOT NULL,
quizId INT(6) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br>";
try {
// Skapa Answers
$sql = "CREATE TABLE answers (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
answer VARCHAR(64) NOT NULL,
isCorrect BOOLEAN NOT NULL,
questionId INT(6) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br>";
try {
// Skapa Quizusers
$sql = "CREATE TABLE quizUsers (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
type VARCHAR(5) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br>";
try {
// Skapa Results
$sql = "CREATE TABLE results (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
playerId INT(6) NOT NULL,
quizId INT(6) NOT NULL,
score INT(6) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
}
?>
<!-- Formulär för att välja en tabell att radera -->
<form action="" method="post">
<select name="table">
<option>quizes</option>
<option>questions</option>
<option>answers</option>
<option>quizUsers</option>
<option>results</option>
</select>
<input type="submit" value="Radera">
</form>
<!-- Formulär för att skapa tabeller -->
<form action="" method="post">
<input type="submit" name="create" value="Skapa tabeller">
</form>
</body>
</html>