我有几个简单的输入字段和一个提交它的按钮。我想在不加载或刷新页面的情况下提交值。所以我正在使用JQuery AJAX Post请求。我单独尝试了我的PHP Mysql数据库脚本,它工作正常。但问题是AJAX返回成功,但我的数据库没有更新。
$.ajax({
type: 'POST',
url: "routesave.php?one=" + rt + "&two=" + st + "&three" + lat + "&four" + lon + "&five" + eta,
success: function(response) {
alert('yay ajax is done.');
} //close succss params
});
和PHP
<?php
$route = $_GET['one'];
$stop = $_GET['two'];
$lat = $_GET['three'];
$lon = $_GET['four'];
$eta = $_GET['five'];
sql = new mysqli('localhost','root', '', 'digitrack' );
if ($sql->connect_error) {
die("connection failed:". $sql->connect_error);
}
$query = $sql->query("insert into routes (route, stop, lat, lon, eta) values ('$route', '$stop', '$lat', '$lon' , $eta) ");
if ($query!=TRUE) {
echo "error".$sql->error;
}
?>