lux00r Posted April 25, 2007 Share Posted April 25, 2007 i have a form posting data to 1 tablein a db, inside the first db table i will be asigning aunique row id to the form data. then inside the samepost script i will be inserting the data into moretables, how would i assign the unqiue id assigned inthe first db insertion to the remaining db tables? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 25, 2007 Share Posted April 25, 2007 If you set it as a uniqueID and auto increment it should put the numbers in there by itself without you even having to worry about putting data into it. Quote Link to comment Share on other sites More sharing options...
lux00r Posted April 25, 2007 Author Share Posted April 25, 2007 i know how to set the auto_increment id for the first table, i need to use that generated id for subsequent different table inserts during the same post script. for example: form data -> post script -> table 1 insert (id assigned) -> table 2 insert (take id assigned in table 1) . I need to connect 4 different tables using the id generated Quote Link to comment Share on other sites More sharing options...
mpharo Posted April 25, 2007 Share Posted April 25, 2007 Just use the same variable name in the subsequent insert statements.... $value="TEST"; $select1=mysql_query("SELECT * FROM table1 WHERE value='$value' "); $select2=mysql_query("SELECT * FROM table2 WHERE value='$value' "); $select3=mysql_query("SELECT * FROM table3 WHERE value='$value' "); Quote Link to comment Share on other sites More sharing options...
lux00r Posted April 25, 2007 Author Share Posted April 25, 2007 i understand your concept of using the same value = test. However, would it be possible to use the id value that is created during the first table insert auto increment function, which is handled by mysql db. form data -> post script -> table 1 insert (id created with auto_increment column) -> table 2 insert (use the id created from table 1) Quote Link to comment Share on other sites More sharing options...
lux00r Posted April 25, 2007 Author Share Posted April 25, 2007 i found the solution: <?php $account_query="INSERT INTO accounts (account_id,type) VALUES (NULL,'saving')"; $transaction_query="INSERT INTO transactions(transaction_id,account_id) VALUES (NULL,LAST_INSERT_ID)" ; $a_query=mysql_query($account_query); $t_query=mysql_query($transaction_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.