如何在mysql中生成唯一的id? [重复]

This question already has an answer here:

I would like to know how to generate a unique id for every visitor in mysql. I would also like to know how I can place it at the end of a url, like so: http://example.com/?id=12345

</div>

You can insert the new user as a row in a table which has an auto-increment primary key column and then use php function mysql_insert_id(). That will give you the last inserted id, which is unique.

As of putting it as the end of the URL, you can just add it (simple string concatenate) to the href="" of the links, but that's probably a bad design, so I strongly recommend not to recognize users by some parameter they're passing in GET. You should never need it. Use sessions, cookies, etc...

Use PHP's built-in uniqid function

For retrieving id from the url


    $userID = $_GET['id'];
    

I really must second what Giacomo said about NOT using an id that is shown to the world, but if you want home work try http://www.tizag.com/phpT/phpsessions.php for basic sessions info. But if you are storing personal info and heaven forbid credit card info or the like you must be careful with how you use sessions, Google "session security hole" and you will get About 263,000 results. In short use session but don't use it if your not going to do it right.