keithwtaylor Posted June 24, 2009 Share Posted June 24, 2009 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); ?> Quote Link to comment Share on other sites More sharing options...
RussellReal Posted June 24, 2009 Share Posted June 24, 2009 there is nufin wrong with this code.. idk about jQuery, as I never used jQuery, but usually ajax has to be initialized. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.