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 Link to comment https://forums.phpfreaks.com/topic/172295-id/ 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. Link to comment https://forums.phpfreaks.com/topic/172295-id/#findComment-908414 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. Link to comment https://forums.phpfreaks.com/topic/172295-id/#findComment-908417 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 Link to comment https://forums.phpfreaks.com/topic/172295-id/#findComment-908420 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.