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
https://forums.phpfreaks.com/topic/163564-jquery-php-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.