-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkajax.php
107 lines (80 loc) · 3.4 KB
/
workajax.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
<?php
session_start();
if($_SESSION['username']) {
if (isset($_POST['key'])) {
$connection = new mysqli('localhost', 'root', '', 'restaurant');
if ($_POST['key'] == 'getRowData') {
$rowId = $connection->real_escape_string($_POST['rowId']);
$sql = $connection->query("select w_id,w_name,w_address,mobile_no,gender,mg_id from workers where w_id='$rowId'");
$data = $sql->fetch_array();
$jsonArray = array(
'woid' => $data['w_id'],
'woname' => $data['w_name'],
'woaddress' => $data['w_address'],
'mobileno' => $data['mobile_no'],
'gender' => $data['gender'],
'mgid' => $data['mg_id'],
);
exit(json_encode($jsonArray));
}
if ($_POST['key'] == 'getExistingData') {
$start = $connection->real_escape_string($_POST['start']);
$limit = $connection->real_escape_string($_POST['limit']);
$sql = $connection->query("select w_id,w_name,w_address,mobile_no,gender,mg_id from workers LIMIT $start,$limit");
if ($sql->num_rows > 0) {
$response = "";
while ($data = $sql->fetch_array()) {
$response .= '
<tr>
<td>' . $data[0] . '</td>
<td id="worker_' . $data[0] . '">' . $data[1] . '</td>
<td>' . $data[2] . '</td>
<td>' . $data[3] . '</td>
<td>' . $data[4] . '</td>
<td>
<input type="button" onclick="edit(' . $data[0] . ')" value="Edit" class="btn btn-primary">
<input type="button" onclick="deleteRow(' . $data[0] . ')" value="Delete" class="btn btn-danger">
</td>
</tr>
';
}
exit($response);
} else {
exit('reachedMax');
}
}
$rowId = $connection->real_escape_string($_POST['rowId']);
if ($_POST['key'] == 'deleteRow') {
$connection->query("delete from workers where w_id='$rowId'");
exit('The worker has been deleted');
}
$wid = $connection->real_escape_string($_POST['wid']);
$wname = $connection->real_escape_string($_POST['wname']);
$waddress = $connection->real_escape_string($_POST['waddress']);
$mno = $connection->real_escape_string($_POST['mno']);
$gen = $connection->real_escape_string($_POST['gen']);
$mgid = $connection->real_escape_string($_POST['mgid']);
if ($_POST['key'] == 'updateRow') {
$connection->query("update workers set w_id='$wid', w_name='$wname',w_address='$waddress',mobile_no='$mno',gender='$gen',mg_id='$mgid' where w_id='$rowId'");
exit('successfully updated');
}
if ($_POST['key'] == 'addNew') {
$sql = $connection->query("select * from workers where w_id='$wid'");
if ($sql->num_rows > 0)
exit("The worker ID is already exists");
else {
$connection->query("insert into workers VALUES('$wid','$wname','$waddress','$mno','$gen','$mgid')");
exit('worker item is inserted');
}
}
}
}
else
{
?>
<script>
document.location="index.php";
</script>
<?php
}
?>