-
Notifications
You must be signed in to change notification settings - Fork 1
/
editmenu.php
54 lines (39 loc) · 1.55 KB
/
editmenu.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
<?php
/**
* Created by IntelliJ IDEA.
* User: mithishri
* Date: 10/2/2016
* Time: 12:27 AM
*/
session_start();
if (isset($_SESSION['id'])
&& isset($_SESSION['type'])
&& $_SESSION['type'] == 'admin'
&& isset($_POST['item_id'])
) {
include('conn.php');
if ($_POST['type'] == 'update') {
$query = "UPDATE menu_items
SET name = '" . $_POST['name'] . "',
category = '" . $_POST['category'] . "',
rate = " . $_POST['rate'] . "
WHERE id = " . $_POST['item_id'];
} else if ($_POST['type'] == 'insert') {
$query = "INSERT INTO menu_items (res_id, name, category, rate)
VALUES ('" . $_POST['res_id'] . "', '" . $_POST['name'] . "', '" . $_POST['category'] . "', " . $_POST['rate'] . ");";
} else if ($_POST['type'] == 'delete') {
$query = "DELETE FROM menu_items
WHERE id = " . $_POST['item_id'];
}
if (mysqli_query($link, $query)) {
$response['message'] = '<div class="floating-alert alert alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
Menu Updated.
</div>';
} else $response['message'] = '<div class="floating-alert alert alert-danger">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<strong>Oh Snap!</strong> Unable to update.
</div>';
$response['id'] = mysqli_insert_id($link);
print_r(json_encode($response));
}