65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
include 'koneksi.php';
|
|
|
|
header('Content-Type:application/json;charset=UTF-8');
|
|
|
|
$id_user = $_POST['id_user'];
|
|
$tkp = $_POST['tkp'];
|
|
$jumlah_kejahatan = $_POST['jumlah_kejahatan'];
|
|
$jarak_tkp_polres = $_POST['jarak_tkp_polres'];
|
|
$status = $_POST['status'];
|
|
|
|
$sql_check = "SELECT * FROM kasus_training WHERE tkp = '$tkp'";
|
|
$sql_id_terakhir = "SELECT * FROM kasus_training ORDER BY id_kasus_training DESC LIMIT 1";
|
|
|
|
$result_check = $koneksi->query($sql_check);
|
|
$result_id_terakhir = $koneksi->query($sql_id_terakhir);
|
|
|
|
$id_terakhir = 0;
|
|
|
|
if ($result_id_terakhir->num_rows > 0) {
|
|
$id = 0;
|
|
while ($row = $result_id_terakhir->fetch_assoc()) {
|
|
$id = $row['id_kasus_training'];
|
|
}
|
|
$id_terakhir = $id + 1;
|
|
} else {
|
|
$id_terakhir = 1;
|
|
}
|
|
|
|
if ($tkp == "" || $jumlah_kejahatan == "" || $jarak_tkp_polres == "" || $status == "") {
|
|
echo json_encode(array(
|
|
'message' => 'Gagal! Harap Isi Bagian Yang Belum Terisi',
|
|
'success' => false
|
|
));
|
|
} else if ($result_check->num_rows > 0) {
|
|
echo json_encode(array(
|
|
'message' => 'TKP Sudah Ada!',
|
|
'success' => false,
|
|
));
|
|
} else {
|
|
$sql = "INSERT INTO kasus_training SET
|
|
id_kasus_training = '$id_terakhir',
|
|
id_user = '$id_user',
|
|
tkp = '$tkp',
|
|
jumlah_kejahatan = '$jumlah_kejahatan',
|
|
jarak_tkp_polres = '$jarak_tkp_polres',
|
|
status = '$status'
|
|
";
|
|
|
|
$result = $koneksi->query($sql);
|
|
|
|
if ($result) {
|
|
echo json_encode(array(
|
|
'message' => 'Kasus Training Berhasil Diinputkan',
|
|
'success' => true,
|
|
));
|
|
} else {
|
|
echo json_encode(array(
|
|
'message' => 'Gagal Input Kasus Training',
|
|
'success' => false
|
|
));
|
|
}
|
|
}
|