Current location: Hot Scripts Forums » Other Discussions » Database » Get Unique Id Or Last Inserted Id

Get Unique Id Or Last Inserted Id

  #1 (permalink)  
Wannabe Coder
Join Date: Aug 2009
Posts: 127
Thanks: 16
Thanked 0 Times in 0 Posts
Get Unique Id Or Last Inserted Id

Hi All,

Can anyone tell me how can i get a last inserted unique user id. Following is my Scenario

Every-time a user is created in my website, all his info will be stored in "user" table except his image details. For image, i am using another table "user_images".

PHP Code:

("INSERT INTO `user` (username,password,age,gender) Values ('avc','****','12','1')"); // First user info enters into table
$userid mysql_insert_id();   // bring last inserted id.
mysql_query ("INSERT INTO `user_images`(`user_id`,  `title`, `original_filename`, `stored_filename`, `content_type`)VALUES ('$userid','$title','$realname','$filename','$contenttype')");  // inserted the row with mysql_insert_id as userid 
// user_id field is unique in the table 

Now, my only issue is if two users are doing this at a time. Is there a possibility of they might be having same "mysql_insert_id" and as user_id in "user_images" table is unique, one user ends up with not storing his image info. Can anyone tell me if it is the correct way to do it?

If there is anyother way to do this, please suggest me.
Reply With Quote

Featured Marketplace Scripts (view more)



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
unique visitor per category eldaniel7 Script Requests 1 01-10-10 09:53 PM
Protecting your Software Products with a unique Key System domado16 The Lounge 2 04-20-08 06:11 PM
Generating a unique number? subnet_rx Perl 1 06-12-07 07:24 PM
Case Study: Unique Visitors Kobra The Lounge 2 12-12-06 08:04 AM

All times are GMT -5. The time now is 10:37 PM.
vBulletin® Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.