-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_by_title.php
60 lines (40 loc) · 1.33 KB
/
get_by_title.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
<?php
/*
Symbol: CHn means location of code use find feature in your editor will be easy to find, CHn->CHn means must look at both code
To make it work on your project config these: CH1, CH2, CH3, CH4, CH5, CH6, CH7
*/
header("Contrnt-Type: application/json");
require_once("connection.php");
// CH1->
if (isset($_GET["title"])) {
// CH2->CH4
$title = $_GET["title"];
// CH3
$query = "SELECT * FROM movie WHERE title = ?";
$query = $connection->prepare($query);
// CH4
$query->bind_param("s", $title);
$response = array();
$query->execute();
$result = $query->get_result();
if ($result->num_rows > 0) {
// CH5->CH6
$movie = array();
$result = $result->fetch_assoc();
foreach ($result as $key => $value) {
// CH6->CH7
$movie[$key] = $value;
}
$response["erro"] = false;
// CH7
$response["movie"] = $movie;
$response["massage"] = "response succesfully";
$response["response_code"] = 200;
} else {
$response["erro"] = true;
$response["massage"] = "failed to response becuause there is no data";
$response["response_code"] = 400;
}
echo json_encode($response);
}
?>