Jump to content

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/101894-very-simple-php-increment-not-mysql/
Share on other sites

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

 

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 :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.