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! Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. 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.