1

我试图插入数据库,但它给了我一个错误(检查与您的 mysql 服务器版本相对应的手册,以了解在 (Long,Lat,name,ReturnAddress, Division) 附近使用的正确语法

我正在使用 php,mysql。我需要成功的结果,

 //Insert new row with user data
        $query = sprintf("INSERT INTO map " .
        " ( Id, Lat, Long, Name, ReturnAddress, Division ) " .
        " VALUES ('%s','%s', '%s', '%s', '%s','%s');",
         mysql_real_escape_string($ID),
         mysql_real_escape_string($lat),
         mysql_real_escape_string($lng),
                 mysql_real_escape_string($name),
                 mysql_real_escape_string($address),
                 mysql_real_escape_string($type));


$result = mysql_query($query);

if (!$result) {
  die('Invalid query: ' . mysql_error());
}

mysql_close();

和代码:

<!DOCTYPE html >
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps JavaScript API v3 Example: Map Simple</title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    var marker;
    var infowindow;

    function initialize() {
      var latlng = new google.maps.LatLng(37.4419, 36.1419);
      var options = {
        zoom: 10,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      var map = new google.maps.Map(document.getElementById("map-canvas"), options);
      var html = "<table>" +
                 "<tr><td>Name:</td> <td><input type='text' id='name'/> </td> </tr>" +
                 "<tr><td>Address:</td> <td><input type='text' id='address'/></td> </tr>" +
                 "<tr><td>Type:</td> <td><select id='type'>" +
                 "<option value='normal home' SELECTED>normal home</option>" +
                 "<option value='villa'>villa</option>" +
                 "</select> </td></tr>" +
                 "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
    infowindow = new google.maps.InfoWindow({
     content: html
    });

    google.maps.event.addListener(map, "click", function(event) {
        marker = new google.maps.Marker({
          position: event.latLng,
          map: map
        });
        google.maps.event.addListener(marker, "click", function() {
          infowindow.open(map, marker);
        });
    });
    }

    function saveData() {
      var name = escape(document.getElementById("name").value);
      var address = escape(document.getElementById("address").value);
      var type = document.getElementById("type").value;
      var latlng = marker.getPosition();

      var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address +
                "&type=" + type + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();

        }
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          alert(request.responseText);
          callback(request.responseText, request.status);
           window.open('index.php','_self',false);
        }
      };

      request.open('GET', url, true);
      request.send();
    }

    function doNothing() {}
    </script>
  </head>

  <body style="margin:0px; padding:0px;" onload="initialize()">
    <div id="map-canvas" style="width: 500px; height: 300px"></div>
    <div id="message"></div>
  </body>

</html>

和数据库:

CREATE TABLE IF NOT EXISTS `map` (
  `Id` int(20) NOT NULL AUTO_INCREMENT,
  `Lat` float NOT NULL,
  `Long` float NOT NULL,
  `Name` varchar(100) NOT NULL,
  `ReturnAddress` varchar(100) NOT NULL,
  `Division` varchar(100) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
4

1 回答 1

4

long是一个保留字,用反引号括起来

`long`
于 2013-09-25T11:03:38.450 回答