Jump to content

jQuery & PHP query


keithwtaylor

Recommended Posts

Hi everyone,

 

I hope someone can help me! I track clicks on my web pages by adding, for example, onclick="trackClick('index.php: Sports');" to each of my links. trackClick is defined below and uses the jQuery $.post function to run the server-side PHP code which adds a record in a MySQL table. The PHP snippet is below too. It works, BUT... if a click a link and wait 5 seconds or so, then click a link, and wait 5 seconds or so, then click another - none of these will be recorded in the database. However, if I click a link, and then quickly click on the same (or any other) link, then the second click is recorded in the database. I can't understand why the first click is not recorded, or why the time delay between clicks has any relevance. Anybody got any ideas, I would very much appreciate your help!

 

function trackClick(linkDescription) {

  $.post("trackClick.php", {linkDesc: linkDescription});

}

 

<?php

  header("Cache-Control: no-cache");

  @mysql_connect("localhost", $dbusr, $dbpwd);

  @mysql_select_db("mydb");

  $link = $_REQUEST['linkDesc'];

  $query = "INSERT INTO clicks (dt, link) VALUES (NOW(), '$link')";

  @mysql_query($query);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.