-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateTable.php
More file actions
54 lines (49 loc) · 1.34 KB
/
createTable.php
File metadata and controls
54 lines (49 loc) · 1.34 KB
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
<?php
// Include config file
require_once "config.php";
session_start();
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
header("location: login.php");
exit;
}
if($_SESSION["username"] != "admin") {
die("You do not have permission to access this page.");
}
$sql = "CREATE TABLE forms (
userID INT NOT NULL,
FOREIGN KEY (userID) REFERENCES users(id),
firstname VARCHAR(50) NOT NULL,
lastname VARCHAR(50) NOT NULL,
email VARCHAR(50) NOT NULL,
gender CHAR(1) NOT NULL,
country VARCHAR(25) NOT NULL,
birthdate date NOT NULL,
comment VARCHAR(1500),
submited_at DATETIME DEFAULT CURRENT_TIMESTAMP
);";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CreateDB</title>
<link rel="stylesheet" href="./style.css">
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<?php
if($conn->query($sql)) {
echo "<div class=\"alert green\">Table forms created successfully</div>";
} else {
echo "<div class=\"alert red\">Error creating table: " . $conn->error . "</div>";
}
?>
</body>
</html>