-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-insert.php
More file actions
25 lines (17 loc) · 755 Bytes
/
api-insert.php
File metadata and controls
25 lines (17 loc) · 755 Bytes
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
<?php
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Access-Control-Allow-Headers,Content-Type, Access-Control-Allow-Methods, Authorization, X-Requested-With');
$data = json_decode(file_get_contents("php://input"), true);
$name = $data['sname'];
$age = $data['sage'];
$city = $data['scity'];
include "config.php";
$sql = "INSERT INTO students(student_name, age, city) VALUES ('{$name}', {$age}, '{$city}')";
if(mysqli_query($conn, $sql)){
echo json_encode(array('message' => 'Student Record Inserted.', 'status' => true));
}else{
echo json_encode(array('message' => 'Student Record Not Inserted.', 'status' => false));
}
?>