zebaron Posted June 13, 2007 Share Posted June 13, 2007 Hi, I've only been working with PHP and MySQL for about the last month and half and have done fairly well but have run into a problem that I hope has an answer. I'm working on a simple, small animation showcase site where people I know (animators) can post their animations/movies. Visitors can then "tag" their movies with descriptive words. If I submit a form to insert the mysql row that has an auto-incrementing ID # on it into a table, is there a way to retrieve that ID immediately and use it in that same query to insert the ID # into another table (which I use to cross-reference the table that contains all of my movies's info and the table that contains the information I want to be able to relate to that user)? SO, more plainly I want to: - Retrieve from a form/page the movieID and tag - Insert "tag" into "tags" table of my database, which automatically assigns each tag row an ID - Pull the tagID for the tag row that was just created from the tags table <- Where I need the help - Insert the tagID and movieID into a crossref table Any help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/55357-solved-retrieve-mysql-rows-auto-increment-in-query/ Share on other sites More sharing options...
pocobueno1388 Posted June 13, 2007 Share Posted June 13, 2007 EDIT: mysql_insert_id() is what your looking for. I think you can use it right in your query. It will return the last inserted ID for the current DB connection. Quote Link to comment https://forums.phpfreaks.com/topic/55357-solved-retrieve-mysql-rows-auto-increment-in-query/#findComment-273599 Share on other sites More sharing options...
zebaron Posted June 14, 2007 Author Share Posted June 14, 2007 Thanks a lot, it worked. Quote Link to comment https://forums.phpfreaks.com/topic/55357-solved-retrieve-mysql-rows-auto-increment-in-query/#findComment-274283 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.