この質問をするのは私が初めてではないはずなので、このサイトを検索してみました。サイトに地図を配置し、ユーザーにマーカーと情報を追加してもらいたいと考えています。これは正常に機能していますが、情報が保存されていません。保存して閉じるボタンをクリックしても何も起こりません。どこが間違っているのか誰か教えてください。これがhtmlコードです
var マーカー; var 情報ウィンドウ;
function initialize() {
var latlng = new google.maps.LatLng(-24.532226,31.290586);
var options = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var html = "<table>" +
"<tr><td>Posted by:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Time +/-:</td> <td><input type='text' id='time'/></td> </tr>" +
"<tr><td>Sighting:</td> <td><select id='sighting'>" +
"<option value='Lion' SELECTED>Lion</option>" +
"<option value='Rhino'>Rhino</option>" +
"<option value='Elephant'>Elephant</option>" +
"<option value='Buffalo'>Buffalo</option>" +
"<option value='Leopard'>Leopard</option>" +
"<option value='Cheetah'>Cheetah</option>" +
"<option value='Spotted Hyena'>Spotted Hyena</option>" +
"<option value='Wild Dogs'>Wild Dogs</option>" +
"<option value='Hippo'>Hippo</option>" +
"<option value='Kudu'>Kudu</option>" +
"<option value='Zebra'>Zebra</option>" +
"<option value='Fish Eagle'>Fish Eagle</option>" +
"<option value='Other'>Other</option>" +
"</select> </td></tr>" +
"<tr><td>Description:</td> <td><input type='text' id='description'/> </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 time = escape(document.getElementById("time").value);
var sighting = escape(document.getElementById("sighting").value);
var description = escape(document.getElementById("description").value);
var url = "phpsqlinfo_addrow.php?name=" + name + "&time=" + time +
"&sighting=" + sighting + "&description" + description + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
downloadUrl(url, function(data, responseCode) {
if (responseCode == 200 && data.length <= 1) {
infowindow.close();
document.getElementById("msg").innerHTML = "Location added.";
}
});
}
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 doNothing() {}
</script>
するとこれが体内で
<div id="map">
<body style="margin:0px; padding:0px;" onload="initialize()">
<div id="map-canvas" style="width: 950px; height: 534px"></div>
<div id="msg"></div>
そして、これは私のPHPです
<?php
require("phpsqlinfo_dbinfo.php");
// Gets data from URL parameters
$name = $_GET['map_client_name'];
$time = $_GET['client_time'];
$lat = $_GET['client_lat'];
$lng = $_GET['client_lng'];
$description = $_GET['client_description'];
$sighting = $_GET['client_sighting'];
// Opens a connection to a MySQL server
$connection = mysql_connect ("mysql.spri.co.za", "sean_sql", "Paaseiers01");
if (!$connection) {
die('Not connected : ' . mysql_error());
}
// Set the active MySQL database
$db_selected = mysql_select_db($kruger_park_live, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
// Insert new row with user data
$query = sprintf("INSERT INTO tbl_maps " .
" (ID, map_client_name, client_time, client_lat, client_lng, client_description,
client_sighting) " .
" VALUES (NULL, '%s', '%s', '%s', '%s', '%s', '%s');",
mysql_real_escape_string($name),
mysql_real_escape_string($time),
mysql_real_escape_string($lat),
mysql_real_escape_string($lng),
mysql_real_escape_string($description),
mysql_real_escape_string($sighting));
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
?>
誰かが私を助けてくれませんか、私はこれを4日間続けてきましたが、今はあきらめました. どうもありがとうございました