更新mysql数据库中的单元格时出现问题?

093gszye  于 2021-06-23  发布在  Mysql
关注(0)|答案(0)|浏览(300)

我有一个googleMapweb应用程序,用户可以点击googleMap标记,在弹出的窗口中进行选择,然后点击submit。它使用ajax用用户选择的信息更新数据库。数据库中预先填充了标记名和gps坐标,这些标记和坐标将被加载。在通过xml加载时,标记也相应地放置。
我在更新数据库中一个名为quest的行时遇到了问题,当它被提交时,用户选择了信息。目前,用户可以选择一个标记并提交一个任务,但它根本不会更新数据库。我不确定该用哪句话。这是我当前的sql语句,我正在尝试更新一个名为quest的行。

mysqli_query($con, "UPDATE markers SET quest= '$questName'  WHERE markerName = '$markerName'");

下面是mymap函数中的downloadurl函数

downloadUrl("call2.php", function(data) {
    var xml = data.responseXML;
    var markers = xml.documentElement.getElementsByTagName("marker");
    for (var i = 0; i < markers.length; i++) {
      var name = markers[i].getAttribute("markerName");
    //  var address = markers[i].getAttribute("address");
  var type = markers[i].getAttribute("type");
  var point = new google.maps.LatLng(
      parseFloat(markers[i].getAttribute("lat")),
      parseFloat(markers[i].getAttribute("longg")));
  var icon = customLabel[type] || {};
  var marker = new google.maps.Marker({
    map: map,
    position: point,
    icon: icon.icon,
    shadow: icon.shadow
  });
  bindInfoWindow(marker, map, infoWindow, html);
}
});

这就是按下提交按钮时发生的情况。

if (document.getElementById("questType").value == 
"quest1") { //if quest1 is selected upon submission
alert("quest1");
var markerName;
var questName = "Quest 1";

xmlhttp = new XMLHttpRequest(); //Creating the 
XMLHttpRequest object           
xmlhttp.open("GET", "ajax.php?questName=" + questName 
+ "&markerName=" + markerName, true); //Specifying the type of request to the server                    
xmlhttp.send(); //Sending the request to the server

下面是我的相关ajax.php。

<?php 
include("connect.php");
require("call.php");

if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . 
mysqli_connect_error();     
} else  {   

} 

$markerName = mysqli_real_escape_string($con, 
$_GET['markerName']);
$questName = mysqli_real_escape_string($con,$_GET['questName']);
$lat = mysqli_real_escape_string($con, $_GET['lat']);
$longg = mysqli_real_escape_string($con, $_GET['longg']);
mysqli_query($con, "UPDATE markers SET quest= 
'$questName'  WHERE markerName = '$markerName'");
mysqli_close($con);

这是我的相关通话文件。

$dom     = new DOMDocument("1.0");
$node    = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
include('connect.php');
$query  = "SELECT * FROM markers WHERE 1"; // Select all the rows in the markers table
$result = mysqli_query($con, $query);
if (!$result) {
die('Invalid query: ' . mysqli_error($con));
}

// Iterate through the rows, adding XML nodes for each
while ($row = mysqli_fetch_assoc($result)) {
global $dom, $node, $parnode;

    $node    = $dom->createElement("marker");
    $newnode = $parnode->appendChild($node);
    $newnode->setAttribute("markerName", 
    $row['markerName']);
    $newnode->setAttribute("quest", $row['quest']);
    $newnode->setAttribute("lat", $row['lat']);
    $newnode->setAttribute("longg", $row['longg']);
}

header("Content-type: text/xml");
echo $dom->saveXML();

我没有得到任何错误,但是当我在chrome的network选项卡中的ajaxphp上悬停时,它看起来好像得到了questname,但是markername仍然没有定义。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题