Hi everybody,

Please bear with me I am having a very strange problem. I am having a table that is used to store complaints registered by users.

The primary key is auto incremented. But I have another field i.e. token_id it is also incremented by 1 every time a new entry is inserted in the table and this should be unique.

token_id is incremented in PHP code. What I do is, before adding a value in the database, first I get the maximum token_id and then I add 1 to it. Then I use this value for token_id.

But I have realized there are many duplicate token_id in the table. I have rechecked my PHP code and there is no error within this. There is also a complaint_date field that stores date and time. For some entries the date and time are same even seconds, but some entries are entered in the table with a difference of 1 to 2 minutes and some with seconds after.

There are almost 4800 users who are accessing the website. Is it possible when I use the query "select max(token_id) as token_value from table", and simultaneously many users are accessing the website and they are having the same max_id and it is used in the table that is causing the problem.

There are many users who are using the website at the same time and registering complaints.
One other thing is that, many people may be using a relatively slow internet connection.

At database level I can avoid duplicate entries by creating a unique index in the table for token_id, but why I am having duplicate entries for token_id when my PHP code is correct.


Any help would be appreciated, I never had such kind of strange issue before.
Thanks in Advance,