-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatain.php
63 lines (46 loc) · 1.65 KB
/
datain.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
<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
// get database connection
include_once './database.php';
// instantiate account object
include_once './data.php';
$database = new Database();
$db = $database->getConnection();
$newdata = new Data($db);
// get posted data
$data = json_decode(file_get_contents("php://input"));
// make sure data is not empty
if(
!empty($data->Action)
){
// set product property values
$newdata->Action = $data->Action;
// $account->created = date('Y-m-d H:i:s');
// create the product
if($newdata->datain()){
// set response code - 201 created
http_response_code(201);
// tell the user
echo json_encode(array("Code" => "0", "Message" => "", "Result" => array("IsOK" => true)));
}
// if unable to create the product, tell the user
else{
// set response code - 503 service unavailable
http_response_code(503);
// tell the user
echo json_encode(array("Code" => "0", "Message" => "Unable to create account.", "Result" => array("IsOK" => false)));
}
}
// tell the user data is incomplete
else{
// set response code - 400 bad request
http_response_code(400);
// tell the user
echo json_encode(array("Code" => "0", "Message" => "Unable to create account. Data is incomplete.", "Result" => array("IsOK" => false)));
}
?>