Dynamic creation of the SQL structure
diff --git a/admin/createtable.php b/admin/createtable.php
index ca5f2d6..375225b 100644
--- a/admin/createtable.php
+++ b/admin/createtable.php
@@ -3,8 +3,9 @@
require '../php/utils.php';
$dbname = $_GET['dbname'];
+ $mortsname = $dbname . "_morts";
- $create = "CREATE TABLE `".$dbname."` (
+ $queries = ["CREATE TABLE `$dbname` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`nom` varchar(100) CHARACTER SET utf8 COLLATE utf8_spanish_ci NOT NULL,
`curs` tinyint(1) NOT NULL,
@@ -12,19 +13,18 @@
`quimata` int(11) NOT NULL,
`requested` tinyint(1) NOT NULL DEFAULT 0,
`mort` tinyint(1) NOT NULL DEFAULT 0,
- `password` varchar(100) NOT NULL DEFAULT ''
- )";
-
- /*
- CREATE TABLE `morts` (
+ `password` varchar(100) NOT NULL DEFAULT '',
+ `bits` int(3) NOT NULL
+ )",
+ "CREATE TABLE `$mortsname` (
`id` int(11) NOT NULL,
`quimatava` int(11) NOT NULL,
`assassi` int(11) NOT NULL,
`curs` tinyint(1) NOT NULL,
`grau` tinyint(1) NOT NULL,
`data` date NOT NULL DEFAULT current_timestamp()
- )
- */
-
- if (query($create)) die("<script>window.location.href = './index.php?dbname=".$dbname."'<script>");
+ )"];
+
+ foreach ($queries as $query) if (!query($query)) die('An error ocurred.');
+ die("<script>window.location.href = './index.php?dbname=$dbname'</script>");
?>
diff --git a/admin/insert.php b/admin/insert.php
index e357105..6f793a1 100644
--- a/admin/insert.php
+++ b/admin/insert.php
@@ -14,8 +14,8 @@
foreach ($inscrits as $user) {
$i = ($i + 1) % ($start + count($inscrits));
if ($i == 0) $i = $i + 1;
- $template = "INSERT INTO `".$dbname."` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`)" .
- " VALUES (NULL, '".$user[0]."', '".$user[1]."', '".$user[2]."', ".$i.", '0', '0', '')";
+ $template = "INSERT INTO `".$dbname."` (`id`, `nom`, `curs`, `grau`, `quimata`, `requested`, `mort`, `password`, `bits`)" .
+ " VALUES (NULL, '".$user[0]."', '".$user[1]."', '".$user[2]."', ".$i.", 0, 0, '', ".(int)rand(1,512).")";
if (!query($template)) die("An error ocurred.");
}