dmblesley Posted January 5, 2007 Share Posted January 5, 2007 I am entering data into table#1 which gives and autoincrement number (id). I would like to have that id number placed into table#2. Right now I have insert commands. How do I take the autoincrement id # from table #1 and place it into table #2?Thanks: dmblesley Link to comment https://forums.phpfreaks.com/topic/32978-entering-id-numbers-into-multiple-tables/ Share on other sites More sharing options...
paul2463 Posted January 5, 2007 Share Posted January 5, 2007 [code]<?php$query = "INSERT INTO table_1 (information) VALUES (other information)";mysql_query($query)or die ('Error in query: $query. ' . mysql_error());$idvalue = mysql_insert_id(); // the id of the last insert statement$query1 = "INSERT INTO table_2(id_from_table1) VALUES ('$idvalue')"; //or UPDATE if the row is already theremysql_query($query)or die ('Error in query: $query. ' . mysql_error());?>[/code] Link to comment https://forums.phpfreaks.com/topic/32978-entering-id-numbers-into-multiple-tables/#findComment-153585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.