我使用谷歌地理编码器获取地址的纬度和经度。 我可以看到,在我的JS代码中,数字返回正常。 但是在将它们发送到我的PHP文件并插入到Mysql DB之后,我只得到了零。 DB中的列是double。 手动插入数字而不是地理编码器结果时,它可以正常工作。
有什么想法吗? 谢谢!
这是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');
}
})
}
});
这是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);
?>