-
Notifications
You must be signed in to change notification settings - Fork 1
/
adddeptdb.php
109 lines (65 loc) · 1.79 KB
/
adddeptdb.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
<?php
include("config/config.php");
//set password and username for new user (first time user) to database
$name=$_POST["departmentname"];
$pass=$_POST["passwrd1"];
$hmail=$_POST["headmail"];
$dimg=$_POST["deptimg"];
$sqlque="select * from user where email='".$hmail."' AND usertype='User'";
$res_u=mysqli_query($con,$sqlque);
//echo mysqli_num_rows($res_u);
if (mysqli_num_rows($res_u) == 1) {
$sql="insert into department (dname,deptimg) values('$name','$dimg')";
mysqli_query($con,$sql);
$sql="update user set name='$name',username='$name',email='$hmail',password='$pass',usertype='Department' where email='$hmail';";
///echo $sql;
mysqli_query($con,$sql);
echo'
<html>
<body>
<script src="assets/js/plugins/sweetalert2.js"></script>
<script>
swal("Department Added","","success");
setTimeout(function(){
window.location.href = "./admindashboard.php";
},1000);
</script>
</body>
</html>
';
}
else{
$sqlque="select * from user where (username='".$name."' OR email='".$hmail."')AND usertype='Department'";
$res_u=mysqli_query($con,$sqlque);
if (mysqli_num_rows($res_u) == 0)
{
$sql="insert into department (dname,deptimg) values('$name','$dimg')";
mysqli_query($con,$sql);
$sql="insert into user (name,username,email,password,usertype) values('$name','$name','$hmail','$pass','Department')";
mysqli_query($con,$sql);
echo'
<html>
<body>
<script src="assets/js/plugins/sweetalert2.js"></script>
<script>
swal("Department Added","","success");
setTimeout(function(){
window.location.href = "./admindashboard.php";
},1000);
</script>
</body>
</html>
';
}
else{
echo' <html>
<body>
<script>alert( "Already exists" );
window.location ="adddepartment.php";
</script>
</body>
</html>
';
}
}
?>