Dovresti usare ajax.
codice:
<script>
function createObject() {
var xmlhttp = null;
if (window.ActiveXObject) {
if (navigator.userAgent.toLowerCase().indexOf("msie 5") != -1) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}
if (!xmlhttp && typeof(XMLHttpRequest) != 'undefined') {
xmlhttp = new XMLHttpRequest()
}
return xmlhttp;
}
var where =abcde
var http = new createObject();
http.open('GET','insert.php?var='+where);
http.send(null);
</script>
Poi ovviamente la pagina "insert.php" conterrà il codice php per inserire la variabile $_GET['var'] nel database.