Show sourcecode
The following files exists in this folder. Click to view.
admin.php
confirmSignIn.php
createadmin.php
logIn.php
signIn.php
start.php
startsida.php
style.css
tables.php
update.php
tables.php
138 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
<?php
/** @var PDO $dbconn */
include ("start.php");
if ($_COOKIE["type"] != "admin") {
header("location: logIn.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 Players
$sql = "CREATE TABLE JassPlayers (
playerid INT(16) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
type VARCHAR(30) NOT NULL,
mail VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully <br>";
} catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
try {
// Skapa GamePlayers
$sql = "CREATE TABLE GamePlayers (
playerid INT(16) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
gameid INT(30)
)";
$dbconn->exec($sql);
echo "Table created successfully <br>";
} catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
try {
// Skapa Games
$sql = "CREATE TABLE JassGames (
gameid INT(16) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
maxplayers INT(6) NOT NULL,
trumf VARCHAR(30),
isprivate BOOLEAN NOT NULL,
ownerid INT(6) NOT NULL,
code VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully";
} catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
try {
// Skapa PlayerCards
$sql = "CREATE TABLE JassPlayerCards (
cardid INT(16) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
playerid INT(6) NOT NULL,
color INT(6) NOT NULL,
value VARCHAR(30) NOT NULL,
position VARCHAR(30) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully <br>";
} catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
echo "<br><br>";
try {
// Skapa PlayedCards
$sql = "CREATE TABLE JassPlayedCards (
cardid INT(16) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
playerid INT(6) NOT NULL,
color INT(6) NOT NULL,
value VARCHAR(30) NOT NULL,
boardposition INT(6) NOT NULL
)";
$dbconn->exec($sql);
echo "Table created successfully <br>";
}
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>JassPlayers</option>
<option>GamePlayers</option>
<option>JassGames</option>
<option>JassPlayerCards</option>
<option>JassPlayedCards</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>