-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_once.php
136 lines (108 loc) · 2.88 KB
/
run_once.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html>
<head>
<style>
body
{
background-color: lightblue;
}
</style>
</head>
<body>
<!-- //Code to create database -->
<?php
//i am using Example (MySQLi Object-Oriented) with php to create a connection to the database.
$servername = "localhost";
$username = "Administrator";
$password = "#Kalizen0123";
$dbname="voting";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br>";
// Create database ---initialize only once
$sql = "CREATE DATABASE voting";
if ($conn->query($sql) === TRUE) {
echo "Database 'voting' created successfully<br>";
} else {
echo "Error creating database:" . $conn->error;
echo "<br>";
}
$conn->close();
?>
<!-- //Code to create tables -->
<?php
//i am using Example (MySQLi Object-Oriented) with php to create a connection to the database.
$servername = "localhost";
$username = "Administrator";
$password = "#Kalizen0123";
$dbname="voting";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully<br>";
// sql to create table
$sql = "CREATE TABLE candidate (
candidate_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
position VARCHAR(100) NOT NULL,
firstname VARCHAR(100) NOT NULL,
lastname VARCHAR(100) NOT NULL,
gender VARCHAR(100) NOT NULL,
img VARCHAR(100)
)";
if ($conn->query($sql) === TRUE) {
echo "Table candidate created successfully<br>";
} else {
echo "Error creating table:" . $conn->error;
echo "<br>";
}
$sql = "CREATE TABLE user (
user_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL,
firstname VARCHAR(100) NOT NULL,
lastname VARCHAR(100) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table user created successfully<br>";
} else {
echo "Error creating table:" . $conn->error;
echo "<br>";
}
//FOREIGN KEY FOR ID NUMBER YET TO BE IN PLACE
$sql = "CREATE TABLE voters (
voters_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
id_number INT(11) NOT NULL,
password VARCHAR(100) NOT NULL,
firstname VARCHAR(100) NOT NULL,
lastname VARCHAR(100) NOT NULL,
status VARCHAR(100) NOT NULL,
account VARCHAR(100) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table voters created successfully<br>";
} else {
echo "Error creating table:" . $conn->error;
echo "<br>";
}
//WEAK ENTITY SET need foreign keys
$sql = "CREATE TABLE votes(
vote_id int(255) NOT NULL,
candidate_id varchar(255) NOT NULL,
voter_id VARCHAR(255) NOT NULL
)";
if ($conn->query($sql) === TRUE) {
echo "Table votes created successfully<br>";
} else {
echo "Error creating table:" . $conn->error;
echo "<br>";
}
$conn->close();
?>
</body>
</html>