'Missing required fields']); exit; } $db = getDB(); $stmt = $db->prepare('INSERT INTO roads (name, status, length, coordinates) VALUES (?, ?, ?, ?)'); $stmt->execute([ $data['name'], $data['status'], (float)$data['length'], json_encode($data['coordinates']) ]); echo json_encode([ 'success' => true, 'id' => $db->lastInsertId(), 'name' => $data['name'], 'status' => $data['status'], 'length' => (float)$data['length'], 'coordinates' => json_encode($data['coordinates']) ]); } catch (Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } } else { http_response_code(405); echo json_encode(['error' => 'Method not allowed']); } ?>