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,
Thank you for your quick reply.
Actually complaint_id is used for our purpose, and token_id is given to customers who are registering complaints. We want to keep these things separate. They are given a token_id to track their complaint. So the idea is to use two fields one for admin purposes and one for customer purposes.
One other thing, I have just noticed after having a look on my PHP code.
We are also allowing users to upload attachments, and the limit is up to 2MB. And I am querying the table before uploading the file. In other words, I store token_id into a variable, then script uploads a file. If successful I insert the record in the database. Is it possible while a file is being uploaded another users registers a complaint with same token_id?