Generating Consecutive Numbers

I have an html form that will be accessed by many users. I want to add a field that will automatically generate consecutive tracking numbers beginning with 04-01. How can I accomplish this?
contesaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
aolXFTConnect With a Mentor Commented:
It's not the only way, but it is probably the easiest.

If you are doing it through a flat file you have to lock the file whilst it is in use by one program, to prevent two programs from gaining access to it at the same time. Check out www.php.net/flock .

Alternatively if you didn't want to lock the file, you could simply on each invocation, add one character(lets say 'x') to the file. This would be fairly a fairly atomic operation, so it wouldn't really matter if two files wrote to the same file, at the same time, because they would both be simply appending, a letter. The downside to this is that the file could get fairly large, if you have a busy site(namely no_of_hits * 1byte). This can be an advantage however in that in order to see the amount of visitors you have all you have all you have to do is check the file size. I would NOT recommend this however for a busy site.

/**
 *
 * Code to add a letter to a file each time a file is accessed.
 * This code has not been tested, and the concept only occured to
 * the author halfway through writing the message on EE
 *
 * This code may not be used in connection to the Nuclear Industry or
 * anything else that could get me in trouble. By using this code the
 * user assumes full responsability, and concedes to the non-existance
 * of any implied, or stated warrenty.
 *
 * @author aolXFT@Experts-Exchange
 */
function add_visitor_record(){
      $filename = "visitor_record.dat";
      return fwrite(fopen($filename, "a"), 'x', 1);
}

function get_visitor_count(){
      return filesize("visitor_record.dat");
}
0
 
venkateshwarrCommented:

you have to use some server-side scripting language like asp/php etc..
to do this.
0
 
ljfernandezCommented:
You will have to store the users' ids on the server side. Are you using any server programming on your site?

0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
COBOLdinosaurCommented:
You will also have to store the number somewhere server side. a simple file of a table that associates the user and the number.  Depending on the environment and how you are going to use it, you might also be able to use environmental or global variables.

Cd&
0
 
aolXFTCommented:
If you just need a tracking number why not use the Session ID?
0
 
contesaAuthor Commented:
The users accessing the form are many. I don't need user ids tied to the tracking numbers. I just need a number generated on the form so that I can track how many forms have been submitted.

How can I use the Session ID as a tracking number?

Be kind, I'm a newbie to programming.
0
 
COBOLdinosaurCommented:
If you just need a count, then just put the number in a text file and update from you forms processing script.  Every submit has to go through the script, so that is the place to do it.

Cd&
0
 
FataquiCommented:
Hi


What web programming language(s) do you have available on the server.


Fataqui!
0
 
contesaAuthor Commented:
Hi COBOLdinosaur and Fataqui,

I am new to this field. I am running my sites on a Windowss 2000 server. I didn't set up the server so I'm not sure what available. However, I can have my network manager install whatever I need.

COBOLdinosaur, how exactly do I code the text file?

I'd appreciate any  help you can offer.

Thank you.
0
 
COBOLdinosaurCommented:
The file is easy just use notepad and put the starting number in it.  Then you just have to modify the script that processes the form to update the number in the file each time the form gets submitted to it.

Cd&
0
 
aolXFTCommented:
Personally I'd suggest using a database for this. It might at first seem overkill, but if you simply use a file, you have to lock the file, before opening it. A _Simple_ database would be easeir. all you have to do is each time the script is run, execute  a query like:

update count_table set count_column=count_column + 1;

Databases generally do their own synchronising. By that I mean if two scripts open a file at the same time, and read the same value, they will both write a number one abve the original, when you want two above the orig. This is especially important on potentially busy sites.
0
 
contesaAuthor Commented:
aolXFT,

Is using a database the only way to avoid writing one above the original instead of two if the form is accessed simultaneously by more than one user?

0
 
contesaAuthor Commented:
Hi, AOLfxt

I haven't forgotten about this problem.  However, I'm working on the form mail issue right now and I don't want to add another variable until my query works correct in the script.

I will definitely try this solution as soon as I get the form mail issue to work right.

Thanks for all of your help.
0
 
contesaAuthor Commented:
Hi AOLfxt,

Thank you very much for all of your help.  We are actually testing the accepted answer but at the same time we are working on a database. We have realized that a database is much better for this situation.

Thanks again.
0
All Courses

From novice to tech pro — start learning today.