I'm trying to make a basic download counter work. Right now it kinda works, but I'm facing 2 issues.

This is my code:
Code: Select all
   $GLOBALS['template_name'] = $_GET['p1'];
   $GLOBALS['page_id'] = $_GET['p2'];
   echo "template name: ".$GLOBALS['template_name'];
   echo "".$GLOBALS['page_id'];

   _masterpage= $GLOBALS['template_name'];
   _page_id= $GLOBALS['page_id'];
   page_downloads="<cms:add page_downloads '1' />"

And this is my jQuery:
Code: Select all
$('.download-button').click((event) => {
   let target = $(event.target),
        t_name: string = target.data("t-name"),
          p_id: string = target.data("p-id"),
        counterURL = "/download.php?p1=" + t_name + "&p2=" + p_id;


ajaxRequest(url: string): void {
   $.post(url, (res) => {
      console.log("call went through");

The issues I'm facing are:

1. Currently I'm using static data to increase the downloads field for each item. So instead of
Code: Select all
_masterpage= $GLOBALS['template_name'];
_page_id= $GLOBALS['page_id'];

(which is how the final code is supposed to be I think) I'm actually passing
Code: Select all
_masterpage= 'index.php';
_page_id= 67;

This is because I get 'ERROR: Tag "db_persist" - _masterpage does not exist' (data bound forms is uncommented in kfunctions.php). I'm pretty sure that it's because of the way I'm passing the variables to the db_persist tag.

2. Second issue: as I said, right now I'm using dummy data, so it (kinda) works. The problem is that the page_downloads field only goes from 0 to 1, and no more than that.

It might be that I'm missing something (or a lot of things). Can anyone give some feedback?


Note: '/downloads.php' is a file in the root of the project. All it does is embed the 'download-counter.php' snippet.