-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.php
69 lines (45 loc) · 2.18 KB
/
api.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
<?php
include("mysqlconnect.php");
header("content-type:application/json");
if(isset($_GET['action']) && $_GET['action'] == 'list'){
$isPictura = (int) filter_var($_GET['isPictura'], FILTER_VALIDATE_BOOLEAN);
$query_list = "SELECT * FROM images_tbl WHERE isPictura = '$isPictura' ORDER BY submission_date";
$result = mysql_query($query_list) or die("error in $query_list == ----> ".mysql_error());
$jsonResponse = array();
$index = 0;
while($row = mysql_fetch_assoc($result)){
$jsonResponse[$index] = $row;
$index++;
}
echo json_encode($jsonResponse);
}
if(isset($_POST['action']) && $_POST['action'] == 'delete'){
$id = $_POST['id'];
$query_delete = "DELETE FROM images_tbl WHERE id = '$id'";
mysql_query($query_delete) or die("error in $query_save == ----> ".mysql_error());
$response = array('status' => 'ok', 'msg' => 'Image deleted!');
echo json_encode($response);
}
if(isset($_POST['action']) && $_POST['action'] == 'save'){
$isPictura = (int) filter_var($_POST['isPictura'], FILTER_VALIDATE_BOOLEAN);
$name = $_POST['name'];
$description = $_POST['description'];
$dimensions = $_POST['dimensions'];
$content = $_POST['content'];
$query_save="INSERT into images_tbl (title, description, dimensions, content, isPictura, submission_date) VALUES ('$name', '$description', '$dimensions', '$content', '$isPictura', now());";
mysql_query($query_save) or die("error in $query_save == ----> ".mysql_error());
$response = array('status' => 'ok', 'msg' => 'Image saved!');
echo json_encode($response);
}
if(isset($_POST['action']) && $_POST['action'] == 'update'){
$id = $_POST['id'];
$name = $_POST['name'];
$description = $_POST['description'];
$dimensions = $_POST['dimensions'];
$query_update="UPDATE images_tbl SET title='$name', description='$description', dimensions='$dimensions' WHERE id = '$id'";
mysql_query($query_update) or die("error in $query_update == ----> ".mysql_error());
$response = array('status' => 'ok', 'msg' => 'Image updated!');
echo json_encode($response);
}
exit();
?>