Jump to content

Click Counter


recset

Recommended Posts

I am trying to create a click counter for records in my database with the following code:

[code]
// *** Hits Counter ***
$urlparam = "passit";
$ckrs = "quotes"; //used for identification
if (!isset($HTTP_SERVER_VARS["QUERY_STRING"])) {
  $HitLink = $HTTP_SERVER_VARS["PHP_SELF"] . "?" . $urlparam . "=";
} else {
  $HitLink = $HTTP_SERVER_VARS["PHP_SELF"] . "?" . $HTTP_SERVER_VARS["QUERY_STRING"] . "&" . $urlparam . "=";
}
if (isset($HTTP_GET_VARS[$urlparam])) {
  $tableName = "wisdom_backup";
  $fieldName = "ID";
  $hitsfield = "Counter";
  $urlfield = "PATH";
  // Get the Hits number and update it.
  $rsCon = "vlot";
  $IdSource = "select * from " .  $tableName . " where " . $fieldName . " = " . $HTTP_GET_VARS[$urlparam] . "";
  $rsId = mysql_query($IdSource, $$rsCon) or die(mysql_error());
  $row_rsId = mysql_fetch_assoc($rsId);
  $hiturl = $row_rsId[$urlfield];
  $next = $row_rsId[$hitsfield] + 1;
  $upd = "update " . $tableName . " set " . $hitsfield . " = " . $next . " where " . $fieldName . " = " . $HTTP_GET_VARS[$urlparam] . "";
  $rsId = mysql_query($upd, $$rsCon) or die(mysql_error());
  $rsId = null;
  header("Location: " . $hiturl);
}

[/code]

And this is the code for the actual link:
[code]
<a href="<?php echo $HitLink . $row_quotes["ID"] ?>">Download</a>
[/code]

Now, it does everything that I want it to do (counts hits everytime it is clicked) however, in the URL path,  it adds:
[code]&passit=46[/code]
the '46' refers to the record ID, now if a user keeps on clicking different record ID's, it will keep on adding the 'passit' url parameter, for example it would look like:
[code]
&passit=46&passit=22&passit=34&passit=5
[/code]

And so on and so on. Is there a way to clear the url parameters once the link has been clicked, but still store the data that its supposed to store??



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.