I want to delete specific Markers from my database, I can save than with an “ID”, I wan’t to use the same ID to delete from database,
For example, if I save 20 waypoints, the id of each marker will be (1,2,3,…,20)
I want to use this value on JavaScript and delete a specific line from the table on PHP code,
For example, if I click on a marker on my project, it will automacally delete from map and from database, I have a code here:
EDITED WITH MY TRY
function bindInfoWindow(marker, map, infoWindow, html, deleta) {
google.maps.event.addListener(marker, 'click', function() {
infoWindow.setContent(html);
infoWindow.open(map, marker);
});
google.maps.event.addListener(marker, 'rightclick', function()
{
marker.setVisible(false)
alert(deleta)
deleteMK(deleta)
});
}
function deleteMK(deleta)
{
alert("vai");
var url2 = "phpsqlinfo_addrow.php?deleta=" + deleta;
downloadUrl2(url2, function(data3, responseCode)
{
if (responseText == 200 && data3.length <= 1)
{
document.getElementById("message").innerHTML = "Deletado";
window.location.reload()
}
});
}
var string2 = JSON.stringify(data3)
//Função ajax que salva os marcadores no mapa
function downloadUrl2(url2, callback)
{
var request2 = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
request2.open('POST',url2);
request2.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
request2.send('command=delete&marker='+string2)
request2.onreadystatechange = function()
{
if(request2.readyState==4)
{
//infowindow.close();
alert('Deletado')
}
}
}
PHP:
$deleta = $_REQUEST['deleta]'];
if($_REQUEST['command']=='delete')
{
$query = sprintf("DELETE FROM markers WHERE id='%s'",mysql_real_escape_string($deleta));
}
**What ever you do don’t use unescaped HTML in your query see tutorial
USE**
You should also confirm delete in infobox
I assume you are now using ID column (atocomplete} as I suggested in comment