Need some help with a Counter for a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Selah
Forum Newbie
Posts: 3
Joined: Wed Nov 27, 2002 7:55 am

Need some help with a Counter for a form

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Selah
Forum Newbie
Posts: 3
Joined: Wed Nov 27, 2002 7:55 am

Post 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" ?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could just include() the counter script into the script that processes the form.

Mac
Selah
Forum Newbie
Posts: 3
Joined: Wed Nov 27, 2002 7:55 am

Post 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
Post Reply