Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/projekt/quiz/

createtable.php
dbconnection.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertposts.php
leaderboard.php
log_in.php
log_out.php
main.php
question_maker.php
quiz_form.php
quiz_list.php
quiz_maker.php
result.php
selectposts.php
sign_in.php
style.js
updateposts.php

createtable.php

56 lines UTF-8 Windows (CRLF)
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>

<body>
<?php
include ('dbconnection.php');

// Skapar tabell för användare
try { 

    
// sql to create table
    
$sql "CREATE TABLE quiz_users (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    username VARCHAR(30) NOT NULL,
    password VARCHAR(30) NOT NULL,
    usertype ENUM('user', 'admin') NOT NULL DEFAULT 'user',
    reg_date DATETIME
    )"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

// Skapar tabell för quizzar
try { 

    
// sql to create table
    
$sql "CREATE TABLE quizzes (
    id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
    quiz_name VARCHAR(30) NOT NULL)"
;

    
// use exec() because no results are returned
    
$dbconn->exec($sql);
    echo 
"Table created successfully";
}
catch(
PDOException $e)
    {
    echo 
$sql "<br>" $e->getMessage();
}

//Rensa kopplingen till databasen
$dbconn null;

?>
</body>
</html>