View Full Version : JavaScript and MySQL

05-26-2006, 06:22 PM
I am developing a website what contains links. I want to record down the hit rate of each link by MySQL database. Is it possible to use JavaScript to update the database when user click on the links?

05-29-2006, 02:51 PM
I don't think you can update the database directly from a javascript when you use it client side, as you do. However, you could use what is called Ajax-technology to acomplish this. Then you need a server side script that performs the database update.

Perhaps it would be more easy to use redirecting or something like this:
The link that is supposed to be open is http://www.hiof.no
<a href="link.php?link=http://www.hiof.no">Click here</a>

The link.php file could be something like this:

// Get the link
$link = $_GET["link"];

// Do the database updating
// code here ...

// Go to the requested link
header("Location: {$link}");

05-31-2006, 07:03 AM