-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
110 lines (96 loc) · 3.26 KB
/
init.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require 'CONFIG.php';
$servername = $_SESSION['db-domain'];
$username = $_SESSION['db-user'];
$password = $_SESSION['db-pswd'];
$dbname = $_SESSION['db-name'];
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if($dbname == ""){
echo("You have to specify the name of the databse");
die();
}else if($servername = ""){
echo("You have to sepecify the mysqli server name");
die();
}else if($password = ""){
echo("You have to sepecify the password for the database");
die();
}else if($username = ""){
echo("You have to sepecify the user name for the database");
die();
}
// Check connection
if ($conn->connect_error) {
echo "Could not connect to the SQL Database";
die("Connection failed: " . $conn->connect_error);
}
if ($conn->query("USE $dbname") !== TRUE) {
echo "Error using database: " . $conn->error;
}
$result_sessions = $conn->query("select * from information_schema.tables where table_name='sessions'");
$result_spresp = $conn->query("select * from information_schema.tables where table_name='spresp'");
$result_quresp = $conn->query("select * from information_schema.tables where table_name='quresp'");
/*
$sql = "DROP TABLE sessions";
if ($conn->query($sql) !== TRUE) {
echo "Error dropping table: " . $conn->error;
}
$sql = "DROP TABLE spresp";
if ($conn->query($sql) !== TRUE) {
echo "Error dropping table: " . $conn->error;
}
$sql = "DROP TABLE quresp";
if ($conn->query($sql) !== TRUE) {
echo "Error dropping table: " . $conn->error;
}
*/
// Create tables if they don't exist
if($result_sessions->num_rows == 0) {
$table = "CREATE TABLE sessions (
name INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
id CHAR(4),
mode SMALLINT UNSIGNED,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($table) !== TRUE) {
echo "There was an error creating the table". $conn->error;
}
}
if($result_spresp->num_rows == 0) {
$table = "CREATE TABLE spresp (
name INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
session CHAR(4),
speed SMALLINT,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($table) !== TRUE) {
echo "There was an error creating the table". $conn->error;
}
}
if($result_quresp->num_rows == 0) {
$table = "CREATE TABLE quresp (
name INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
session CHAR(4),
answer SMALLINT UNSIGNED,
date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";
if ($conn->query($table) !== TRUE) {
echo "There was an error creating the table". $conn->error;
}
}
// Store data for future references;
$_SESSION['db-name'] = $dbname;
$_SESSION['conn'] = $conn;
// This is the barrier that every input has to pass before it is inserted in the mysql search.
function cleanCode($name){
if (get_magic_quotes_gpc()) {
$name = stripslashes($name);
}
$name = mysqli_real_escape_string($_SESSION['conn'], $name);
if (strlen($name) != 4) {
echo("The input didn't have the correct length");
die();
}
return $name;
}
?>