Page 1 of 1

Need some help with a Counter for a form

Posted: Wed Nov 27, 2002 7:55 am
by Selah
i need some help with this counter i'm creating.

it is supposed to be a counter that that increment every time the form on the page is submited.

eg: this form has been submitted ** times

and hel would be appreciated

Posted: Wed Nov 27, 2002 8:00 am
by twigletmac
You're going to have to store the number somewhere - would you be wanting to do this into a database or just a simple text file? Then all you have to do is take that number add 1 to it each time the form is submitted and save it back to the database or text file.

Mac

Posted: Wed Nov 27, 2002 8:17 am
by Selah
This is my counter script below...but it is getting it to increment when the form submits and view it on the same page

<?

$counter_file = "/../../count.txt";
$counter_file_line = file($counter_file);
$counter_file_line[0]++;

// opends the file and then writes the new number and then closes it
$cf = fopen($counter_file, "w");
fputs($cf, "$counter_file_line[0]");
fclose($cf);

// prints out the full count
echo $counter_file_line[0];
?>

Do i call the script in the form tag action="counter.php" ?

Posted: Wed Nov 27, 2002 8:20 am
by twigletmac
You could just include() the counter script into the script that processes the form.

Mac

Posted: Wed Nov 27, 2002 8:24 am
by Selah
Thanks man...i'll have the concept figured out i'll just mess around with the code from here.

any problems...i'll know where to post