Check if valid coordinate

This commit is contained in:
Daniel Løvbrøtte Olsen 2016-05-16 12:07:42 +02:00
parent b6bb4c13df
commit 925e55b741

View File

@ -37,12 +37,12 @@ if (!TableExists($config["db_table"], $conn)) {
echo "Please don't leave any fields blank"; echo "Please don't leave any fields blank";
exit(); exit();
} }
printf("\r\n");
printf($_POST["Latitude"]); if(addToTable($_POST["Latitude"], $_POST["Longtitude"], "test", $config["db_table"], $conn) == false)
printf("\r\n"); {
printf($_POST["Longtitude"]); echo "Please enter a valid coordinate";
addToTable($_POST["Latitude"], $_POST["Longtitude"], "test", $config["db_table"], $conn); exit();
}
} }
?> ?>
@ -90,10 +90,13 @@ function TableExists($table, $conn) {
} }
function addToTable($lat, $lon, $url, $table, $conn) { function addToTable($lat, $lon, $url, $table, $conn) {
$lat = mysqli_real_escape_string($conn, $lat); if (is_numeric($lat) == false || is_numeric($lon) == false ||
$lon = mysqli_real_escape_string($conn, $lon); $lat > 180 || $lat < -180 ||
settype($lat, "double"); $lon > 180 || $lon < -180)
settype($lon, "double"); {
return false;
}
$sql = "INSERT INTO `" . $table . "` (`id`, `location`, `url`, `date_added`) VALUES (NULL, GeomFromText('POINT(" . $lon ." " . $lat . ")',4326), 'test', CURRENT_TIMESTAMP)"; $sql = "INSERT INTO `" . $table . "` (`id`, `location`, `url`, `date_added`) VALUES (NULL, GeomFromText('POINT(" . $lon ." " . $lat . ")',4326), 'test', CURRENT_TIMESTAMP)";
//printf($sql); //printf($sql);
$res = mysqli_query($conn, $sql); $res = mysqli_query($conn, $sql);