I Have some trouble with php script.
I want to run mysql Query on php code when i click some link..
There is my code
<?php
function hello(){
$browser=$_SERVER['HTTP_USER_AGENT'];
$url="http://".$_SERVER[SERVER_NAME].$_SERVER[REQUEST_URI];
$ip=$_SERVER['REMOTE_ADDR'];
mysql_connect("localhost","root","") or die("cannot connect");
mysql_select_db("kpp924");
mysql_query("INSERT INTO logs(ip,url,link,browser,waktu) VALUES ('$ip','$url','http://www.google.com','$browser','this is waktu')");
mysql_close();
}
?>
<a href="http://www.google.com" onclick="document.write('<?php hello() ?>');" >Click to save log</a>
This code got work, when i click on the link, the value inserted to the database. But my problem is, When i open the page, the function is running, an new data inserted to the database without clicking on the link.
is something wrong with my code?? can please anything tell me where is the mistake. or maybe someone can be solve it with javascript??