last day (15 days later) » 

5:40 PM
-1
Q: Button click counter

codekI'm working on this page I'm trying to create a button click counter that on every download it increases. I want to use it without a database, this is the code: <?php $counterFile = 'counter.txt' ; // jQuery ajax request is sent here if ( isset($_GET['increase']) ) { ...

 
I remember this piece of code. You got that from stackoverflow.com/a/26892053 in your other question. By using that code, you should have accepted the answer, or upvoted it. I ran that orignal code and it did not always stay at 0, but did in fact increment in value. I actually helped in that answer to point out errors made, but no further comments were given on your part.
 
Yeah, I'm not saying in any part of the question I did the code, I was going to accept it but I need to make it work before accepting the answer. As you can see it's not working for me or do you see it working with my setup?
 
I did not imply that you did the code and calling it your own. You should have posted a comment under the person's answer to let that person know why it's not working, instead of posting a new question using the code.
 
@Fred-ii- Ok, my bad, sorry. Do you want me to delete this question? I should have thought of doing it that way :/
 
It's up to you. But you've gotten an answer and a comment about return false;. Leave it open, but do upvote the other answer if you haven't already and maybe letting that person know of the current problem you are having. What I think may be happening is this url : '/test.php', you're using a / in there which may be a contributing factor, as I stated in the other answer about that. If it's showing as zero, then it's not writing to the file. Using error reporting would signal an error.
To add, url : '/test.php', the test.php part of it, is the PHP for the counter. I'll take a wild guess and say that you have your PHP "and" JS all in one file, right?
 
5:40 PM
@Fred-ii- Yeah, I have already upvoted it. As for the url : '/test.php' I think it's working ok now since I'm not getting this error: download btn: ajax fail : url of ajax request is not reachable
I have all this code in one file if that is what you mean
 
Yes, that's what I meant. You need to seperate your PHP from your JS. The PHP part that you have "is" the url : '/test.php' - JS is to call that file in order to call PHP and tell it to call your counter file and increase it with every click. Plus in conjunction with the answer below, have you seen it?
 
I got it. That was the problem!
 
hehehe, right on! I knew you'd get it ;)
 
Hi man, are you there?
 
yep
 
5:42 PM
I found another problem and I don't know if it is worth to do another question. The problem is that the counter works for all books the same
so if I click on this one infonomia.com/books/30-ideas-for-2030
the counter increases for both the same number, it is not separately
 
that would need to be another question and I won't be able to help right now, I've 2 jobs that just came in and need to be tended to. I'll keep an eye out for it though, should you post a new question.
 
ok, thanks! see you later
 
Plus, you'd be better off using a DB for that, instead of a text file.
 
great, thanks man! have good day
 
it would be easier to track individual items, rather than setting up different text files for different files.
you're welcome, you too, cheers
 

last day (15 days later) »