Very simple PHP increment, not MYSQL

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
sean72
Forum Newbie
Posts: 2
Joined: Sat Apr 19, 2008 2:53 pm

Very simple PHP increment, not MYSQL

Post by sean72 »

One of my intranet sites has a very simple, internal order form with a user group of around 50 people. I have been asked to make the simple PHP order form (which came pre-written but I have customized slightly) generate an automatic order number.

I would like to store the number in a simple txt or csv file (or similar), and for each order, load, increment, use and store it again. It would be ideal if there was some way to lock this file so we didn't get duplicates, but the likelihood of two users making an order at the same time are very low. I would need to insert this code segment or routine in the existing PHP file.

I studied programming, so I understand the concepts, but do not know the syntax for PHP very well. Code suggestions should be complete please.

Thank you!
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Very simple PHP increment, not MYSQL

Post by markusn00b »

sean72 wrote:One of my intranet sites has a very simple, internal order form with a user group of around 50 people. I have been asked to make the simple PHP order form (which came pre-written but I have customized slightly) generate an automatic order number.

I would like to store the number in a simple txt or csv file (or similar), and for each order, load, increment, use and store it again. It would be ideal if there was some way to lock this file so we didn't get duplicates, but the likelihood of two users making an order at the same time are very low. I would need to insert this code segment or routine in the existing PHP file.

I studied programming, so I understand the concepts, but do not know the syntax for PHP very well. Code suggestions should be complete please.

Thank you!
Slightly demanding..

Check php.net for the file() functions, using fopen(), fclose(), etc. you can write and save values to a file.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Very simple PHP increment, not MYSQL

Post by John Cartwright »

also flock() for file locking
sean72
Forum Newbie
Posts: 2
Joined: Sat Apr 19, 2008 2:53 pm

Re: Very simple PHP increment, not MYSQL

Post by sean72 »

I don't intend to sound demanding, if that's what you mean. I just don't know PHP very well but know that this is a relatively simple task.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Very simple PHP increment, not MYSQL

Post by John Cartwright »

Yes it a relatively simple task to do. That is all the more reason why we encourage you to take a stab at it. I'm sure I don't have to tell you, but we aren't here to write code for you. The purpose of these forums is to promote the learning of PHP. Now, that doesn't mean people won't write examples here and there, but outright asking for someone to do it for you is not going to fly.

Take a shot at it, and post a little code. We will nudge you along the way, of course. The functions we've mentioned already have examples in the manual too.
Post Reply