-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathaccountinsert.php
138 lines (120 loc) · 4.29 KB
/
accountinsert.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
137
138
<?php
//add dbconnect
include("db.php");
include("db.php");
$fullname = $_POST['fullname'];
$username = $_POST['username'];
$emailaddress = $_POST['emailaddress'];
$device_Id = $_POST['device_Id'];
$password = $_POST['password'];
$position = $_POST['position'];
$committee = $_POST['committee'];
$count = 0;
$squery = mysqli_query($db, "SELECT * FROM accounts WHERE Username = '$username'");
while($row1 = mysqli_fetch_assoc($squery))
{
if ($row1['Username'] != null)
{
echo '<script> alert ("Username already in use")</script>';
echo '<script> window.history.back();</script>';
die();
}
}
if ($position == 'Barangay Captain')
{
$sql = mysqli_query($db, "SELECT * FROM accounts where Position = 'Barangay Captain'");
while($row = mysqli_fetch_assoc($sql))
{
if ($row['Position'] != null)
{
echo '<script> alert ("Only 1 barangay Captain must be added")</script>';
echo '<script> window.history.back();</script>';
die();
}
}
$query = "INSERT INTO accounts(Fullname ,Username, Emailaddress,device_Id,Password,Position,Committee) VALUES ('$fullname', '$username','$emailaddress','$device_Id', '$password', '$position', '$committee')";
if ($db->query($query) === TRUE)
{
echo '<script> alert ("Successful")</script>';
echo '<script> window.history.back();</script>';
}
}
else if ($position == 'Barangay Treasurer')
{
$sql = mysqli_query($db, "SELECT * FROM accounts where Position = 'Barangay Treasurer'");
while($row = mysqli_fetch_assoc($sql))
{
if ($row['Position'] != null)
{
echo '<script> alert ("Only 1 barangay Treasurer must be added")</script>';
echo '<script> window.history.back();</script>';
die();
}
}
$query = "INSERT INTO accounts(Fullname, Username, Emailaddress,device_Id,Password,Position,Committee) VALUES ('$fullname', '$username','$emailaddress','$device_Id', '$password', '$position', '$committee')";
if ($db->query($query) === TRUE)
{
echo '<script> alert ("Successful")</script>';
echo '<script> window.history.back();</script>';
}
}
else if ($position == 'SK Chairman')
{
$sql = mysqli_query($db, "SELECT * FROM accounts where Position = 'SK Chairman'");
while($row = mysqli_fetch_assoc($sql))
{
if ($row['Position'] != null)
{
echo '<script> alert ("Only 1 barangay SK Chairman must be added")</script>';
echo '<script> window.history.back();</script>';
die();
}
}
$query = "INSERT INTO accounts(Fullname, Username, Emailaddress,device_Id,Password,Position,Committee) VALUES ('$fullname', '$username','$emailaddress','$device_Id', '$password', '$position', '$committee')";
if ($db->query($query) === TRUE)
{
echo '<script> alert ("Successful")</script>';
echo '<script> window.history.back();</script>';
}
}
else if ($position == 'Barangay Councilor')
{
$sql1 = mysqli_query($db, "SELECT * FROM accounts where Position = 'Barangay Councilor'");
while($row = mysqli_fetch_assoc($sql1))
{
$row['Position'];
$count = $count + 1;
}
if ($count >= 7)
{
echo '<script> alert ("Maximum input of Brangay Councilor")</script>';
echo '<script> window.history.back();</script>';
die();
}
$query = mysqli_query($db, "SELECT * from accounts WHERE Committee = '$committee'");
while($row = mysqli_fetch_assoc($query))
{
if ($row['Committee'] != null)
{
echo '<script> alert ("Committee already exist")</script>';
echo '<script> window.history.back();</script>';
die();
}
}
$query = "INSERT INTO accounts(fullname, username, emailaddress,device_Id,password,position,committee) VALUES ('$fullname', '$username','$emailaddress','$device_Id', '$password', '$position', '$committee')";
if ($db->query($query) === TRUE)
{
echo '<script> alert ("Successful")</script>';
echo '<script> window.history.back();</script>';
}
}
else if ($position == 'Barangay Health Worker'){
$query = "INSERT INTO accounts(Fullname, Username, Emailaddress,device_Id,Password,Position,Committee) VALUES ('$fullname', '$username','$emailaddress','$device_Id', '$password', '$position', '$committee')";
if ($db->query($query) === TRUE)
{
echo '<script> alert ("Successful")</script>';
echo '<script> window.history.back();</script>';
echo ' <script> window.location = "account.php"</script>';
}
}
?>