0
我想将用户的HTML5位置插入到数据库中。所以基本上我希望它提交用户在他/她按下提交时的位置。将HTML5位置插入MySQL数据库
HTML5地点代码:
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
我当前的代码:
$post = filter_input(INPUT_POST, 'post', FILTER_SANITIZE_SPECIAL_CHARS);
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_SPECIAL_CHARS);
INSERT INTO news (post, name, date, location) VALUES ('".$post."', '".$name."', '".date('Y-m-d H:i:s')."', '".$location."')
我没有看到任何代码实际发送该位置数据到服务器......你有东西来处理其他表单域,所以我不明白为什么你不能处理地理定位数据... – 2014-12-04 20:04:36
所以你的问题基本上是:如何将js传递给php/sql? – webeno 2014-12-04 20:05:42
您可能正在寻找AJAX将JavaScript数据传输到PHP – Jordy 2014-12-04 20:08:15