-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi-update.php
35 lines (26 loc) · 904 Bytes
/
api-update.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
<?php
header("Content-Type: application/json");
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Mehtods: PUT");
header("Access-Control-Allow-Headers:Access-Control-Allow-Mehtods,Content-Type,Access-Control-Allow-Mehtods,Authorization,X-Requested-With");
/* use id for update record
{
"sid": 2,
"sname": "Prince",
"sage":"24",
"scity":"ferozepur"
}*/
//json format data converted to associative array
$data=json_decode(file_get_contents("php://input"),TRUE);
$id=$data['sid'];
$name=$data['sname'];
$age=$data['sage'];
$city=$data['scity'];
include "config.php";
$sql="UPDATE students SET student_name='{$name}',age={$age},city='{$city}' WHERE id={$id} ";
if(mysqli_query($conn,$sql)){
echo json_encode(array("message"=> "Student Record Updated","status"=> TRUE));
}else{
echo json_encode(array("message"=> "Student Record Can't Updated","status"=> FALSE));
}
?>