INSERT INTO main (`id`, `nazv`, `text`, `user_id`)
VALUES (9, '{$nazv}', '{$text}', '{$user_id}')
ON DUPLICATE KEY UPDATE
`text`=VALUES(`text`),
`nazv`=VALUES(`nazv`),
`user_id`=VALUES(`user_id`);
<?php
private function LatLngDist($p, $q) {
$R = 6371; // Earth radius in km
$dLat = (($q[0] - $p[0]) * pi() / 180);
$dLon = (($q[1] - $p[1]) * pi() / 180);
$a = sin($dLat / 2) * sin($dLat / 2) +
cos($p[0] * pi() / 180) * cos($q[0] * pi() / 180) *
sin($dLon / 2) * sin($dLon / 2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
return $R * $c;
}