hammersm Posted March 20, 2006 Share Posted March 20, 2006 I have two tables, one with the columsUserID , Email (UserID is autoincrementing(the other withUserID , PhoneI have a form that posts the email address and the phone to my handling page. So how do I write a query that enters the email address in the first table then gets the autoincremented UserID. Then enters the Phone in the other table with the same UserID that has just been created by the first INSERT query.I have been trying to do this for ages with no luck.If anyone can help I would be very happy,CheersMark Quote Link to comment Share on other sites More sharing options...
trq Posted March 20, 2006 Share Posted March 20, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I have been trying to do this for ages with no luck.[/quote]Post your code. Quote Link to comment Share on other sites More sharing options...
ober Posted March 20, 2006 Share Posted March 20, 2006 You cannot do that all in one query.INSERT INTO table1 (col1, col2) VALUES (val1, val2)run query$new_id = mysql_insert_id($result);INSERT INTO table2 (col1, col2) VALUES ($new_id, val2)run query 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.