/
add.php
executable file
·101 lines (96 loc) · 2.91 KB
/
add.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
<?php
include 'connection.php';
function AddUser(){
session_start();
$UID=$_POST['UID'];
$UNAME=$_POST['UNAME'];
$PIN=$_POST['PIN'];
if(!empty($_POST['UID'])) {//checking the 'user' name which is from Sign-In.html, is it empty or have some text
$query = mysql_query("INSERT INTO user(UserId, UserName, Pin) values ('$UID', '$UNAME', '$PIN')") or die(mysql_error()); //Insert Query
if($query) {
Back();
} else{
echo "<script>";
echo"window.location = 'addNewUser.php';";
echo "</script>";
}
}
}
function AddKey(){
session_start();
$KID=$_POST['KID'];
$RNO=$_POST['RNO'];
$STA=$_POST['STA'];
if (!empty($_POST['KID'])) {
$query = mysql_query("INSERT INTO key(KeyId, RoomNo, Status) VALUES ('$KID', '$RNO', '$STA')")or die(mysql_error()); //Insert Query
if ($query) {
Back();
}else{
echo "<script>";
echo"window.location = 'addNewKey.php';";
echo "</script>";
}
}
}
function UpdateUser(){
session_start();
$UID=$_POST['UID'];
$UNAME=$_POST['UNAME'];
$PIN=$_POST['PIN'];
if(!empty($_POST['UID'])) {
$query = mysql_query("UPDATE user SET UserName='$UNAME', Pin='$PIN'WHERE UserId='$UID'") or die(mysql_error()); //Insert Query
if ($query) {
Back();
}else{
echo "<script>";
echo"window.location = 'UserConfiguration.php';";
echo "</script>";
}
}
}
function UpdateKey(){
session_start();
$KID=$_POST['KID'];
$RNO=$_POST['RNO'];
$STA=$_POST['STA'];
if (!empty($_POST['KID'])) {
if ($STA=='Available'){
$query0 = mysql_query("DELETE FROM bookdetails WHERE KeyId='$KID'") or die(mysql_error()); //Insert Query
}
$query = mysql_query("UPDATE key SET RoomNo='$RNO', Status='$STA'WHERE KeyId='$KID'"); //Insert Query
if ($query) {
Back();
}else{
echo "<script>";
echo"window.location = 'KeyConfiguration.php';";
echo "</script>";
}
}
}
function UpdateError(){
session_start();
$SNO=$_POST['SNO'];
$ACH=1;
if (!empty($_POST['SNO'])) {
$query = mysql_query("UPDATE errorhistory SET AdminChecked='$ACH' WHERE SerialNo='$SNO'"); //Insert Query
if ($query) {
Back();
}else{
echo "<script>";
echo"window.location = 'ErrorConfiguration.php';";
echo "</script>";
}
}
}
function Back(){
echo "<script>";
echo "window.location = 'Admin.php';";
echo "</script>";
}
if(isset($_POST['submitEC'])) { UpdateError() ; }
if(isset($_POST['submitKC'])) { UpdateKey() ; }
if(isset($_POST['submitUC'])) { UpdateUser() ; }
if(isset($_POST['submitk'])) { AddKey() ; }
if(isset($_POST['submitu'])) { AddUser() ; }
if(isset($_POST['cancel'])) { Back();}
?>