- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.php
More file actions
Latest commit
145 lines (134 loc) · 3.86 KB
/
Copy pathfunction.php
File metadata and controls
145 lines (134 loc) · 3.86 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
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
139
140
141
142
143
144
145
<?php
//header('location:index.php');
functionconnection(){
try{
$con = mysqli_connect("localhost","root","","hoteldb");
}catch(Exception$e){
echo$e->getMessage();
}
return$con;
}
functionbuild_sql_insert($table, $data) {
try {
$con = connection();
$key = array_keys($data);
$val = array_values($data);
$sql = "INSERT INTO $table (" . implode(', ', $key) . ") " . "VALUES ('" . implode("', '", $val) . "')";
$res = mysqli_query($con,$sql);
}catch(Exception$e){
echo$e->getMessage();
}
return($res);
}
functionbuild_sql_check($table, $col_to_check,$val_of_col) {
try {
$con = connection();
$sql = "SELECT * from $table WHERE $col_to_check = '{$val_of_col}'";
$res = mysqli_query($con,$sql);
$row = mysqli_num_rows($res);
}catch(Exception$e){
echo$e->getMessage();
}
return ($row);
}
functionbuild_sql_delete($table, $primary_key ,$value ) {
try {
$con = connection();
$sql = "DELETE from $table WHERE $primary_key = $value";
$res = mysqli_query($con,$sql);
}catch(Exception$e){
echo$e->getMessage();
}
return($res);
}
functionuserlogin($username,$password){
try{
$con = connection();
$sql ="SELECT * from registration where uname='".$username."' and password='".$password."'";
$res = mysqli_query($con,$sql);
$r = mysqli_num_rows($res);
}catch(Exception$e){
echo$e->getMessage();
}
return$r;
}
functionadminlogin($data){
try{
$con = connection();
$sql ="SELECT * from employee where u_name='".$data['u_name']."' and password='".$data['password']."'";
$res = mysqli_query($con,$sql);
$r = mysqli_num_rows($res);
}catch(Exception$e){
echo$e->getMessage();
}
return$r;
}
/* function to build SQL UPDATE string */
functionbuild_sql_update($table, $data,$primary_key,$where)
{
try{
$con = connection();
$cols = array();
foreach($dataas$key=>$val) {
$cols[] = "$key = '$val'";
}
$sql = "UPDATE $table SET " . implode(', ', $cols) . " WHERE $primary_key = $where";
$res = mysqli_query($con,$sql);
$r = mysqli_num_rows($res);
}catch(Exception$e){
echo$e->getMessage();
}
return($r);
}
functionselectalldatabyid($table,$primary_key,$id){
try{
$con = connection();
$cols = array();
$sql = "SELECT * from $table WHERE $primary_key=$id";
$result = mysqli_query($con, $sql);//0 or 1>
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
}catch(Exception$e){
echo$e->getMessage();
}
return($row);
}
functionselectbyusername($u_name){
try {
$con = connection();
$selectalldata = "SELECT * from employee where u_name='".$u_name."'";
$result = mysqli_query($con, $selectalldata);//0 or 1>
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
} catch (Exception$e) {
echo'Message: ' .$e->getMessage();
}
return$row;
}
functioncounttablerows($table){
try {
$con = connection();
$selectalldata = "SELECT * from $table";
$result = mysqli_query($con, $selectalldata);//0 or 1>
$row = mysqli_num_rows($result);
} catch (Exception$e) {
echo'Message: ' .$e->getMessage();
}
/*echo "<pre>";
print_r($row);
echo "</pre>";*/
return$row;
}
functionselectalldataby($table){
try {
$con = connection();
$selectalldata = "SELECT * from $table";
$result = mysqli_query($con, $selectalldata);//0 or 1>
$row = mysqli_fetch_all($result,MYSQLI_ASSOC);
} catch (Exception$e) {
echo'Message: ' .$e->getMessage();
}
/*echo "<pre>";
print_r($row);
echo "</pre>";*/
return$row;
}
?>