soos Posted February 1, 2012 Share Posted February 1, 2012 TABLE 1 id : primary key title category timestamp album_id user_id and TABLE TWO album_id : primary key When inserting values into table one I want create an album for it that would be identifiable with album_id. So, my question is: How do I insert values into both tables in a single query? Thanks for the help in advance. Quote Link to comment Share on other sites More sharing options...
kickstart Posted February 1, 2012 Share Posted February 1, 2012 Hi You can't insert into 2 tables at once. You can insert to the 2nd table, get the last insert id and then use that when inserting into the first table. If you want to make sure it all works you can use commit / rollback. All the best Keith Quote Link to comment Share on other sites More sharing options...
soos Posted February 1, 2012 Author Share Posted February 1, 2012 Hi You can't insert into 2 tables at once. You can insert to the 2nd table, get the last insert id and then use that when inserting into the first table. If you want to make sure it all works you can use commit / rollback. All the best Keith Thanks Keith for you help, but I still don't quite understand. Can you show me an example of how the query should look? (sorry, I'm a newbie in msyql) Quote Link to comment Share on other sites More sharing options...
fenway Posted February 1, 2012 Share Posted February 1, 2012 http://php.net/manual/en/mysqli.insert-id.php 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.