View Full Version : limited submission of a form

07-31-2007, 01:50 AM
hi, I originally posted this in the javascript forum, but it turns out this is the best place to ask.

How would I limit the total number if subscribers to a newsletter. The form wouldhave to redirect them to a newpage explaining that my limit of 50 has been reached and that I wasn't sent their information.

Before that imit is reached, the data from the form they fill out (html of course) would be emailed to me. I am very new to php and I am still lfiguring it out. I would appreciate any input :D Thanks

07-31-2007, 04:51 AM
One easy way is to store the number of subscribers in a flat file. Or, store the email and name of each subscriber in a flat file, then you can simply count the number of subscribers to determine if the currently submitted form should be rejected. Or if you want to go to another level you can create a database (MySQL for example) to store the information, but that's yet another learning curve. (I suggest one learning curve at a time)

Here is your homework:

How to open a new file for writing or reading: fopen() (http://us.php.net/manual/en/function.fopen.php) (study the different modes you use to open files)

How to write a line to an open file: fwrite() (http://us.php.net/manual/en/function.fwrite.php)

Easy way to count the number of records in a file: Use file() (http://us.php.net/manual/en/function.file.php) to build an array from a file's contents, then use count() (http://us.php.net/manual/en/function.count.php) to count the number of records in that array