I have this little click counter. I would like to include each click in a mysql table. Can anybody help?
var count1 = 0;
function countClicks1() {
count1 = count1 + 1;
document.getElementById(p1).innerHTML = count1;
}
document.write('<p>');
document.write('<a href=javascript:countClicks1();>Count</a>');
document.write('</p>');
document.write('<p id=p1>0</p>');
Just in case anybody wants to see what I did:
var count1 = 0;
function countClicks1() {
count1 = count1 + 1;
document.getElementById(p1).innerHTML = count1;
}
function doAjax()
$.ajax({
type: POST,
url: phpfile.php,
data: name=name&location=location,
success: function(msg){
alert( Data Saved: + msg );
}
});
}
document.write('</p>');
document.write('<a href=javascript:countClicks1(); doAjax();>Count</a>');
document.write('</p>');
document.write('<p id=p1>0</p>');
This is phpfile.php which for testing purposes writes the data to a txt file
<?php
$name = $_POST['name'];
$location = $_POST['location'];
$myFile = test.txt;
$fh = fopen($myFile, 'w') or die(can't open file);
fwrite($fh, $name);
fwrite($fh, $location);
fclose($fh);
?>