forked from macxwhale/maxilo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·119 lines (98 loc) · 2.96 KB
/
index.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
111
112
113
114
115
116
117
118
119
<html>
<body>
<p>Welcome</p>
<?php
$dbErr = "";
$db = "";
require("functions.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["db"])) {
$dbErr = "Database Name is required <br>";
} else {
$db = test_input(ucname($_POST["db"]));
}
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Database Name: <br>
<?php echo $dbErr; ?>
<br>
<input type="text" name="db" value="<?php echo $db?>">
<input type="submit" name="submit" value="Install">
</form>
</body>
</html>
<?php
if(isset($_POST["submit"]) && empty($dbErr)){
$servername = "localhost";
$username = "root";
$password = "";
try {
$conn = new PDO("mysql:host=$servername;", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE $db";
// use exec() because no results are returned
$conn->exec($sql);
echo "Database ". $db ." created successfully<br>";
header('Refresh: 3; index.php');
}
catch(PDOException $e)
{
echo "Database " . $db. " ";
}
$dbname = "$db";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// sql to create table
$sql = "CREATE TABLE users (
user_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
fname VARCHAR(30) NOT NULL,
lname VARCHAR(30) NOT NULL,
gender VARCHAR(30) NOT NULL,
id_no INT(200) NOT NULL,
email VARCHAR(50),
username VARCHAR(30) NOT NULL,
hashed_password VARCHAR(200) NOT NULL,
user_type VARCHAR(30) NOT NULL,
user_status VARCHAR(30) NOT NULL,
reg_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)";
// use exec() because no results are returned
$conn->exec($sql);
echo "Table users created successfully";
}
catch(PDOException $e)
{
echo "Already Exist";
}
$dbname = "$db";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// sql to create table
$sql = "CREATE TABLE loans (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT(6) UNSIGNED NOT NULL,
loan DECIAML(8,2) NOT NULL,
rate VARCHAR (30) NOT NULL,
period VARCHAR (20) NOT NULL,
interest DECIMAL (8,2) NOT NULL,
total DECIMAL (8,2) NOT NULL,
user_status VARCHAR(30) NOT NULL,
date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
)";
// use exec() because no results are returned
$conn->exec($sql);
echo "Table loan created successfully";
}
catch(PDOException $e)
{
echo "Already Exist";
}
$conn = null;
}
?>