Initial commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
include "db_config.php";
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"), true);
|
||||
|
||||
$nama = $data['nama'];
|
||||
$status = $data['status'];
|
||||
$panjang = $data['panjang'];
|
||||
$koordinatInput = $data['koordinat'] ?? [];
|
||||
|
||||
if (is_string($koordinatInput)) {
|
||||
$decoded = json_decode($koordinatInput, true);
|
||||
$koordinat = (json_last_error() === JSON_ERROR_NONE) ? json_encode($decoded) : '[]';
|
||||
} else {
|
||||
$koordinat = json_encode($koordinatInput);
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO jalan (nama,status,panjang,koordinat)
|
||||
VALUES ('$nama','$status','$panjang','$koordinat')";
|
||||
|
||||
if($conn->query($sql)){
|
||||
echo json_encode([
|
||||
"status"=>"success",
|
||||
"id"=>$conn->insert_id
|
||||
]);
|
||||
}else{
|
||||
echo json_encode([
|
||||
"status"=>"error",
|
||||
"error"=>$conn->error
|
||||
]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user