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!
Very simple PHP increment, not MYSQL
Moderator: General Moderators
- markusn00b
- Forum Contributor
- Posts: 298
- Joined: Sat Oct 20, 2007 2:16 pm
- Location: York, England
Re: Very simple PHP increment, not MYSQL
Slightly demanding..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!
Check php.net for the file() functions, using fopen(), fclose(), etc. you can write and save values to a file.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Very simple PHP increment, not MYSQL
also flock() for file locking
Re: Very simple PHP increment, not MYSQL
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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Very simple PHP increment, not MYSQL
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.
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.