i'm trying to make a server side and make a rest API to post from android. i make rest API using php codeigniter, but i don't know why i cant post using json format from mobile phone to this. this is always get errors when i post using json format, this is my rest api code for post :
function post_pengajuan() {
$data = $this->input->post();
$apd_pengajuan = $data['apd_pengajuan'];
$list = array(
'id_petugas' => $data['id_petugas'],
'penanggung_jawab' => $data['penanggung_jawab'],
'institusi' => $data['institusi'],
'alamat' => $data['alamat'],
'lat' => $data['lat'],
'long' => $data['long'],
'sifat_pengajuan' => $data['sifat_pengajuan'],
'alasan' => $data['alasan']
);
$query = $this->db->insert('pengajuan', $list);
$id_pengajuan = $this->db->insert_id();
$x = COUNT($apd_pengajuan);
for($i=0; $i<$x; $i++) {
$list[$i] = array(
'id_pengajuan' => $id_pengajuan,
'id_apd' =>$apd_pengajuan['id_apd'][$i],
'jumlah' => $apd_pengajuan['jumlah'][$i]
);
$this->db->insert('apd_pengajuan',$list[$i]);
}
// $this->db->insert_batch('apd_pengajuan',$list);
if($query) {
$data = array(
'status' => "success"
);
} else {
$data = array(
'status' => "error"
);
}
header('Content-Type: application/json', 'Accept: application/json');
echo json_encode($data);
}
when i'm post using this format, it posted :
but when i post using json format, it cant post. it's get error.
{
"id_petugas": "14",
"penanggung_jawab": "zhzhzhdhd",
"institusi": "gghhj",
"alamat": "labangka",
"lat": null,
"long": null,
"sifat_pengajuan": "Urgent",
"alasan": "hhzhzhzhs",
"apd_pengajuan": {
"id_apd": [
2,
4
],
"jumlah": [
15,
13
]
}
}
this is the error when post using json :
<body>
<div id="container">
<h1>A Database Error Occurred</h1>
<p>Error Number: 1048</p>
<p>Column 'id_petugas' cannot be null</p>
<p>INSERT INTO `pengajuan` (`id_petugas`, `penanggung_jawab`, `institusi`, `alamat`, `lat`, `long`,
`sifat_pengajuan`, `alasan`) VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)</p>
<p>Filename: controllers/Api.php</p>
<p>Line Number: 47</p>
</div>
</body>
please help mee :(