I'm using google geocoder to get latitude and longitude on an address. I can see that in my JS code the numbers are returned ok. but after sending them to my PHP file and inserting into the Mysql DB, I get only zeros. The column in the DB is double. When inserting a number manually instead of the geocoder results, it works fine.
Any ideas? Thanks!
This is the JS:
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address.val()}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (isEmptyInputValidation(city) || isEmptyInputValidation(street) || isEmptyInputValidation(addressNumber)){
formValid = false;
redInputError(address);
}
else{
latitude = (results[0].geometry.location).lat();
longitude = (results[0].geometry.location).lng();
}
}
else {
alert("Geocode was not successful for the following reason: " + status);
redInputError(address);
}
});
if(formValid) {
var email = getItemFromLocalStorage('email');
var password = getItemFromLocalStorage('password');
latitude = (results[0].geometry.location).lat();
longitude = 34.885372;
$.ajax({
url: "http://gsbeta.hol.es/php/register-sitter.php",
type: 'POST',
data: $("#form_sitter_registration").serialize() + '&email=' + email + '&password=' + password
+ '&latitude=' + latitude + '&longitude=' + longitude,
success: function(data) {
setCookie("userId", data);
setCookie("firstName", firstName);
setCookie("lastName", lastName);
setCookie("email", email);
setCookie("isParent",0);
//window.location.href = 'search_sitter.html';
},
error: function(error) {
alert('error');
}
})
}
});
This is the php:
<?php
header("Access-Control-Allow-Origin: *");
include 'dbconfig.php';
$email = $_POST['email'];
$password = md5($_POST['password']);
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$street = $_POST['street'];
$address_number = $_POST['address_number'];
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$info = $_POST['info'];
$insert = $conn->query("INSERT INTO users (email, password, first_name, last_name, phone, city, street, address_number, info, is_parent, latitude, longitude)
VALUES ('$email', '$password', '$first_name', '$last_name', '$phone', '$city', '$street', '$address_number', '$info', 0, '$latitude', '$longitude');");
$sitter_id = mysqli_insert_id($conn);
$birthday = date ("Y-m-d H:i:s",strtotime($_POST['month']."/".$_POST['day']."/".$_POST['year']));
$cost_per_hour = $_POST['cost_per_hour'];
$is_mobile = $_POST['is_mobile'];
$youngest_age = $_POST['youngest_age'];
$oldest_age = $_POST['oldest_age'];
$insert = $conn->query ("INSERT INTO sitter (id, birthday, cost_per_hour, is_mobile, youngest_age, oldest_age) VALUES ('$sitter_id', '$birthday', '$cost_per_hour', '$is_mobile', '$youngest_age', '$oldest_age');");
$conn->close();
echo($sitter_id);
?>