sean72 Posted April 19, 2008 Share Posted April 19, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/101894-very-simple-php-increment-not-mysql/ Share on other sites More sharing options...
laffin Posted April 19, 2008 Share Posted April 19, 2008 Use a counter tracker or consider using time(). Counter u shud find a number of tutorials on Quote Link to comment https://forums.phpfreaks.com/topic/101894-very-simple-php-increment-not-mysql/#findComment-521458 Share on other sites More sharing options...
Northern Flame Posted April 19, 2008 Share Posted April 19, 2008 you mean something like this: <?php $myFile = "testFile.txt"; $fh = fopen($myFile, 'r'); $fw = fopen($myFile, 'w'); $id = $fh + 1; echo "Your id is $id"; fwrite($fw, $id); fclose($fh); fclose($fw); ?> be sure to make testFile.txt writable Quote Link to comment https://forums.phpfreaks.com/topic/101894-very-simple-php-increment-not-mysql/#findComment-521460 Share on other sites More sharing options...
laffin Posted April 19, 2008 Share Posted April 19, 2008 Found a simple counter in this forum under tutorials //This is the code for the counter it makes a txt file named counter and it stores // the amount of times its been viewed $TextFile = "counter.txt"; $Count = 0+trim(file_get_contents($TextFile)); $Count++; file_put_contents($TextFile,$Count); very simple, and to the point Quote Link to comment https://forums.phpfreaks.com/topic/101894-very-simple-php-increment-not-mysql/#findComment-521503 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.