Unique Customer ID Numbers

Hi all, I have a table that stores all of our customers, each employee adds their own customers. Currently I’m using rand() to generate a customer ID number. Just concerned that if one-day fate would have it to generate an ID that a customer already has, we’re going to have two customers sharing the same ID, that’s going to cause some serious problems.

Is there a way I can connect to MySQL, see if that id is available if so enter it, if not then generate a unique one. All without the user knowing what’s going on. It needs to be as streamlined as possible.

Any help is appreciated as always :smiley:

Forget randomly generating IDs and just use the database to increment the id filed for every new row. Then you will never have duplicate IDs.

But my problem with doing it like that is that I have multiple users the system at the same time and they might both submit at the same time?

MySQL takes care of that.

Really? That’s awesome, I love that :slight_smile: Actually, just had an idea, I could just use the id which is auto-incremented. Think that’s probably the best way? Rather than finding the highest number and incrementing it by 1.

If MySQL could not handle such a case, it would have died a long time ago. No one is going to use a database that could be messed up by such a case.

That is the only way :slight_smile:

Ok cheers guys, appreciate the help and advice :slight_smile: