0

如果还有另一个类似的帖子,我很抱歉,但是很难用我的问题来正式提出一个问题。所以我有一个带有谷歌地图的页面和两个表格,可以在地图上添加带有额外信息的点。一种形式工作得很好,另一种不太好。我的语言是立陶宛语,所以我有一些特殊字符,例如“ ąčęėįšųū”,并且在提交后使用第二种形式,我在数据库中的值不正确,例如“ %u0117%u0161”。

在此处输入图像描述

在图像编号 1. 中,这种形式运行良好。数字 2. 是出现编码问题的表单,数字 3. 是提交 2 号表单后的结果。

对于第二种形式,我使用了谷歌教程(https://developers.google.com/maps/articles/phpsqlinfo_v3),并编辑了一些小东西。

因此,如果有人能帮助我解决这个问题,我将不胜感激。

Javascript代码:

 function initMap() {
 map = new google.maps.Map(document.getElementById("map"), {
 zoom: 0,
 center: new google.maps.LatLng(55.203953, 24.873047),
 mapTypeId: google.maps.MapTypeId.ROADMAP,
 mapTypeControl: true,
 panControl: true,
 mapTypeControlOptions: {
 style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
 },
 navigationControl: true,
 navigationControlOptions: {
 style: google.maps.NavigationControlStyle.SMALL
 }
 }); 


 var html = "<table>" +
                 "<tr><td>Pavadinimas:</td> <td><input type='text' name='name' id='name'/> </td> </tr>" +
                 "<tr><td>Miestas:</td> <td><input type='text' name='city' id='city'/></td> </tr>" +
                 "<tr><td>Adresas:</td> <td><input type='text' name='adress' id='adress'/></td> </tr>" +
                 "<tr><td>Apibudinimas:</td> <td><input type='text' name='description' id='description'/></td> </tr>" +
                 "<tr><td>Type:</td> <td><select id='type'>" +
                 "<option value='Baras' SELECTED>Baras</option>" +
                 "<option value='Restoranas'>Restoranas</option>" +
                 "<option value='Degalinė'>Degalinė</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);
        });
    });

 center = bounds.getCenter();
 map.fitBounds(bounds); 

  }

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

      var url = "phpsqlinfo_addrow.php?name=" + name + "&adress=" + adress + "&city=" + city +
      "&description=" + description + "&type=" + type + "&lat=" + latlng.lat() + "&lon=" + latlng.lng();
      downloadUrl(url, function(data, responseCode) {
        if (responseCode == 200 && data.length <= 1) {
          infowindow.close();
          document.getElementById("message").innerHTML = "Location added.";
        }

      });

     $(document).ready(function() {
        setTimeout("ReloadPage()", 100);
        });

    }

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

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request.responseText, request.status);
        }
      };

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

    }

    function ReloadPage() {
   location.reload();
};


    function doNothing() {}

PHP插入代码:

require("controller/phpsqlinfo_dbinfo.php");

// Gets data from URL parameters
$name = $_GET['name'];

$adress = $_GET['adress'];

$city = $_GET['city'];

$description = $_GET['description'];

$lat = $_GET['lat'];

$lon = $_GET['lon'];

$type = $_GET['type'];


// Opens a connection to a MySQL server
$connection=mysql_connect ("localhost", $dbuser, $dbpass);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($dbname, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Insert new row with user data

//$submit="INSERT INTO poi_example (id, name, city, adress, description, lat, lon, type) VALUES (NULL,'$name','$city', '$adress','$description','$lat','$lon','$type');";

$query = sprintf("INSERT INTO poi_example " .
         " (id, name, adress, city, description, lat, lon, type ) " .
         " VALUES (NULL, '%s', '%s', '%s', '%s', '%s', '%s', '%s');",
         mysql_real_escape_string($name),
         mysql_real_escape_string($adress),
          mysql_real_escape_string($city),
         mysql_real_escape_string($description),
         mysql_real_escape_string($lat),
         mysql_real_escape_string($lon),
         mysql_real_escape_string($type));

$result = mysql_query($query);


//print_r($result);

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

?>
4

1 回答 1

1

您的(本地?)数据库是否可能未配置为使用正确的编码?我认为例如 UTF-8 可能更适合立陶宛语。我认为 MySQL 的标准编码类似于 latin1?这只是一个猜测,但您可能需要检查一下。

于 2012-10-18T12:48:01.400 回答