-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.php
More file actions
69 lines (48 loc) · 1.54 KB
/
update.php
File metadata and controls
69 lines (48 loc) · 1.54 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
<?php
include './connection.php';
extract($_POST);
$response = array();
if(isset($_POST['readrecord'])){
include './readData.php';
}
if(isset($_POST['id']) && isset($_POST['id']) != "")
{
$user_id = $_POST['id'];
$query = "SELECT * FROM plans WHERE id = '$user_id'";
if (!$result = $conn->query($query)) {
exit(error_log());
}
if($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$response = $row;
}
}
// WILL PRINT 'DATA NOT FOUND' IF THERE IS NO ROW IN THE DATABASE WITH THE SELECTED ID
else
{
$response['status'] = 200;
$response['message'] = "Data not found!";
}
// PHP has some built-in functions to handle JSON.
// Objects in PHP can be converted into JSON by using the PHP function json_encode():
echo json_encode($response);
}
// IF THE SELECTED ID IS NOT AVAILABLE IN DATABASE IT WILL PRINT INVALID REQUEST
else
{
$response['status'] = 200;
$response['message'] = "Invalid Request!";
}
///update table
if(isset($_POST['hidden_plan_id'])){
$hidden_plan_id = $_POST['hidden_plan_id'];
$holiday = $_POST['holiday'];
$priority = $_POST['priority'];
$name = $_POST['name'];
$description = $_POST['description'];
$upquery = "UPDATE plans SET name='$name',priority='$priority',description='$description' WHERE id='$hidden_plan_id'";
if (!$result = $conn->query($upquery)) {
exit(error_log());
}
}
?>