PDA

View Full Version : Simple Counter Needed


BrAinZ
11-07-2002, 10:44 AM
Hello.

I need a bit of help with something that is probably quite simple (once you know what you are doing!).

I have designed an online form for my users to fill in which sends a nice formatted email to a particular department of our company.

BUT.. I need to get it to generate an individual number to be sent with this info to differentiate each time the form has been filled in.

Er.. Does that make sense? It needs to increment by one each time someone sends the form.

What would be the easiest way to do this?

Any help would be appreciated!

N!ck
11-07-2002, 11:45 AM
put this above your mail() line (or above the variable you use for the message)


$fp=fopen("somefile.txt","rw");
$idnumber=fread($fp,filesize("somefile.txt"))+1;
fwrite($fp,$idnumber);
fclose($fp);


chmod somefile.txt 777

BrAinZ
11-07-2002, 05:02 PM
Easy when you know how! ;)

I'll give it a go later and see how I get on.

THANKS!!

BrAinZ
11-07-2002, 06:30 PM
Almost seems to work, although it doesn't seem to increase by 1 each time someone posts the form.

(It's definitely 777)

Any ideas why it's not working ?

BrAinZ
11-13-2002, 04:07 PM
Someone MUST have some ideas.... If so PLEASE take the time to put me out of my misery ;)

THANKS!

telc
11-13-2002, 11:54 PM
Originally posted by BrAinZ
Someone MUST have some ideas.... If so PLEASE take the time to put me out of my misery ;)

THANKS!

<?
if(file_exists("counter.dat")) {
$exist_file = fopen("counter.dat", "r");
$new_count = fgets($exist_file, 255);
$new_count++;
fclose($exist_file);
$MYID = $new_count;
$exist_count = fopen("counter.dat", "w");
fputs($exist_count, $new_count);
fclose($exist_count);
} else {
$new_file = fopen("counter.dat", "w");
fputs($new_file, "1");
$MYID = 1;
fclose($new_file);
}

echo $MYID;
?>


That will work.

BrAinZ
11-19-2002, 06:32 PM
Thanks muxx, I'll give it a go. I appreciate your help!

BrAinZ
11-21-2002, 02:21 PM
Not that I doubted it for a moment.. but it works brilliantly....

A HUGE.. THANKS !!!