dsp77 Posted June 24, 2010 Share Posted June 24, 2010 I have two tables in the data base: first one contains id(auto increment) username pass type the second one contains information about the user and another record idUser. What i need is a mysql query that would insert the user into the first table and at the same time inserting the id(auto increment) from first table in the second table in IdUser record. i tried a few things but none working please help. Thank you! Link to comment https://forums.phpfreaks.com/topic/205722-mysql-insert-id-into-2-tables-dilemma/ Share on other sites More sharing options...
Mchl Posted June 24, 2010 Share Posted June 24, 2010 You can't do this in one query. Link to comment https://forums.phpfreaks.com/topic/205722-mysql-insert-id-into-2-tables-dilemma/#findComment-1076497 Share on other sites More sharing options...
dsp77 Posted June 24, 2010 Author Share Posted June 24, 2010 how can i do it i'm thinking of inserting then export place it in a variable and insert again this means 3 queries? Link to comment https://forums.phpfreaks.com/topic/205722-mysql-insert-id-into-2-tables-dilemma/#findComment-1076498 Share on other sites More sharing options...
Mchl Posted June 24, 2010 Share Posted June 24, 2010 Just two: 1. Insert into first table 2. Use LAST_INSERT_ID() to fetch auto generated ID 3. Insert into second table Link to comment https://forums.phpfreaks.com/topic/205722-mysql-insert-id-into-2-tables-dilemma/#findComment-1076499 Share on other sites More sharing options...
dsp77 Posted June 24, 2010 Author Share Posted June 24, 2010 thank you for your suggestion that lead me to mysql_insert_id () and now it works great. Link to comment https://forums.phpfreaks.com/topic/205722-mysql-insert-id-into-2-tables-dilemma/#findComment-1076527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.