Step 1: Create the HttpRequest
function createXMLHttpRequest() {
var ua;
if(window.XMLHttpRequest) {
try {
ua = new XMLHttpRequest();
} catch(e) {
ua = false;
}
} else if(window.ActiveXObject) {
try {
ua = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
ua = false;
}
}
return ua;
}
Step 2: Create a function where you call your external MySQL
This function executes the file "abmelden.php" with the parameters "t_id" and "k_id".
function abmelden(teilnehmer, kurs) {
var req1 = createXMLHttpRequest();
req1.open('get', 'abmelden.php?t_id=' + teilnehmer + '&k_id=' + kurs);
req1.send(null);
}
Step 3: Write your MySQL-Script
Now just write down your MySQL-Query in the file "abmelden.php" and that's it.
mysql_query("DELETE FROM rechnung WHERE r_t_id ='".$_GET[t_id]."' and r_k_id ='".$_GET[k_id]."'");
You successfully executed your SQL-Query without reloading the page.
Ajax is really great ;)