I am sending data in the form of decimal values using JQuery to a PHP file. The PHP file in turn inserts these values into a MySQL database in which the two columns lat,lng
are of type decimal. It seems that the PHP script, particularly the $_POST variable, undesirably rounds the values. My question is, how do I receive the decimal values in the PHP file without rounding them, so that I can send the unrounded values to the database?
For example: Running the below code resulted in a database entry of 33,57
instead of the expected 32.58285,57.38373
.
sendMarkerData.js:
$(document).ready(function(){
$.ajax({
url:'sendMarkerData.php',
method:'POST',
data:{
lat:32.58285,
lng:57.38373 // sample lat, lng values
},
success:function(data){
console.log(data);
}
})
sendMarkerData.php:
<?php
include ('database_connect.php');
$lat = $_POST['lat'];
$lng = $_POST['lng']; // apparently these two lines round lat and lng to integers
$sqlSend = "INSERT INTO `markers` (`lat`, `lng`) VALUES ($lat, $lng)";
if ($conn->query($sqlSend) === TRUE) {
echo "success";
}
else {
echo "fail";
}
$conn->close();
?>