Jump to content

[SOLVED] Insert a unique AND random 10-digit number (instead of auto-increment)


sKunKbad

Recommended Posts

I'd like a query OR the ability to set a column's properties in the database, so that as I insert a new record, the value of the field in this column would be a unique AND random 10 digit number. I'm using phpMyAdmin, as I'm not a MySQL guru. Can I set the column in the database to generate this type of number, instead of auto-increment? Currently the column is just set as INT w/ auto-increment.

 

I know I could probably do this with multiple queries to the database to confirm that a php generated random number isn't currently in use, but I'm looking for a cleaner way. Is what I want to do possible?

Link to comment
Share on other sites

Well MySQL has a RAND() function, but there still can be a way to have a repeated number. I don't know of any other way but to generate a number and query the DB to see if the number exists. Too troublesome for what its worth.

 

May I ask why you wish to do that?

Link to comment
Share on other sites

Well, I guess I had this idea in my head that my user id's would be more secure if they were random, and not auto-incremented. Even though the rest of the authentication system is secure, it would be much harder to guess a user's ID, in case somebody was trying to modify their cookie (or a cookie).

Link to comment
Share on other sites

I am using session data and a second cookie. The data for authentication is in the session, so I guess there's no point in worrying about cookie modification. I appreciate the response. Sometimes after a long day I get foggy headed.

Link to comment
Share on other sites

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.