This is the second time I've had this problem. I can't remember how I resolved it the first time, so I'm going to post it here.
I have a place where users can post their own views/comments about what I say on my site. Under each of my posts, it has a link to the comments section of that post, and it tells how many comments there has already been.
Obviously, I have to increase this number each time there is a post. It was going fine until tonight, when I changed the way things where done, and I added a login script. This, however, didn't edit any of the coding for the comment-counting.
Now, the problem is, instead of increasing the comment count by one each time there is a comment, it instead increases by 8. If i remember correctly, that's the same number as the last time it was screwing up.
The code is as follows, and is called once in the script which is activated by a form on another page.
function addone($data)
{
$fr = fopen("comments/$data","r");
$count1 = fgets($fr,2000);
fclose($fr);
$fw = fopen("comments/$data","w");
$new_count = ++$count1;
fputs($fw,$new_count);
fclose($fw);
}
It opens the file, adds one, and closes the file. I thought maybe it was looping and calling it 8 times, but it wasn't, because there would then be 8 new comments. There's only 1 new comment, and the count goes up 8.
It baffles me.