我需要帮助处理将我的Google地图标记位置更新为mySQL 所面临的问题。 我想在后台发送此标记的纬度和经度(即无需刷新页面)。我使用过AJAX和PHP但到目前为止没有运气。可能是因为我是两个人的初学者。
以下是我的工作:
需要在 driver.php
中修复的部分/////Get latitude and longitude of the last created marker/////////
lg1= markerStart.getPosition().lng();
lt1= markerStart.getPosition().lat();
////I need help here- Please provide me with solution///////////
$.ajax({
url: "update.php",
type: "POST",
data: {'xCordinates': lg1,'yCordinates': lt1}
/*,
success: function () {
alert("ok");// This works
}*/
});
//alert(lg1+","+lt1); // This works (I get accurate altitude and longitude)
update.php
<?php
session_start();
$driverId = $_SESSION['driver_id'];
$driver_name = $_SESSION['name'];
include "header.php"; // access database
$xCordinates = $_POST['xCordinates']; // take value of xCordinates
$yCordinates = $_POST['yCordinates']; // take value of yCordinates
// Do not worry about the spelling mistakes below!
$updatevalue = "UPDATE driver SET xCornidates='$xCordinates', yCornidates='$yCordinates' WHERE driver_id='$driverId'";
$result1 = mysql_query($updatevalue) or die(mysql_error());
?>
我很感激您的解决方案。谢谢!
答案 0 :(得分:0)
试试这个,改变
$updatevalue = "UPDATE driver SET xCornidates='$xCordinates', yCornidates='$yCordinates' WHERE driver_id='$driverId'";
到
$updatevalue = "UPDATE driver SET xCornidates=$xCordinates, yCornidates=$yCordinates WHERE driver_id=$driverId";
但考虑重组以避免sql注入。