unidox Posted August 28, 2009 Share Posted August 28, 2009 I insert a new row inside a table, and the db automatically gives it an ID. I was wondering, how I can obtain that ID without calling the db by one of the row values. Because, I add a user with a user_id and a name, and the name could be anything and possibly match other rows in the db. The col with user_id is auto increment, so I was wondering how I can obtain this while still adding the user to the db. Thanks Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 Do a select to see if that username already exists before doing the insert. Quote Link to comment Share on other sites More sharing options...
unidox Posted August 28, 2009 Author Share Posted August 28, 2009 But I need duplicate names in the db. Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted August 28, 2009 Share Posted August 28, 2009 But I need duplicate names in the db.In that case, do the insert, then use mysql_insert_id() to get the ID that was allocated by the insert Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.