-
Notifications
You must be signed in to change notification settings - Fork 2
/
addToPlanner.php
61 lines (50 loc) · 1.91 KB
/
addToPlanner.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
<?php
require 'connect.php';
header('Access-Control-Allow-Origin: https://engineersabroad.uvacreate.virginia.edu'); //comment out when using localhost
//header('Access-Control-Allow-Origin: http://localhost:4200'); //comment out when using hosted server
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
// get the size of incoming data
//$content_length = (int) $_SERVER['CONTENT_LENGTH'];
// retrieve data from the request
$postdata = file_get_contents("php://input");
// Process data
// (this example simply extracts the data and restructures them back)
if(isset($postdata) && !empty($postdata)){
// Extract json format to PHP array
$request = json_decode($postdata, TRUE);
$email = mysqli_real_escape_string($con, trim($request['email']));
$program = mysqli_real_escape_string($con, trim($request['program']));
$transferredCourses = mysqli_real_escape_string($con, trim($request['transferredCourses']));
$country = mysqli_real_escape_string($con, trim($request['country']));
$sql = "INSERT INTO `planner`(
`email`,
`program`,
`transferredCourses`,
`country`
) VALUES (
'{$email}',
'{$program}',
'{$transferredCourses}',
'{$country}'
)";
if(mysqli_query($con, $sql)){
http_response_code(201);
echo json_encode(true);
}
else{
http_response_code(422);
echo json_encode("Error Adding Planner Object");
}
}
// $data = [];
// $data[0]['length'] = $content_length;
// foreach ($request as $k => $v)
// {
// $data[0]['post_'.$k] = $v;
// }
// // // // Send response (in json format) back the front end
// echo json_encode(['content'=>$data]);
?>