1

データベースに挿入しようとしましたが、エラーが発生しました (mysql サーバーのバージョンに対応するマニュアルを参照して、near (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 に答える