Welcome to WebmasterWorld Guest from 18.104.22.168
I have multiple data from a form search that I want to write to 2 tables. So far that's no problem.
But the incremental IDs (plural!) that are created in TABLE1.ID should be inserted as foreign keys in TABLE2.ID_T1
My first thought was that mysql_insert_id()or last_insert_id() would come in handy - but they just can handle one ID, but I insert several.
Does anybody has clue how to work this out?
$sql = "INSERT INTO table1 (field1)VALUES
('" .implode("'), ('", $_POST['checkbox']) . "')";
mysql_query($sql) or exit(mysql_error());
$sql = "INSERT INTO table2 (id_t1)
SELECT table1.id FROM table1
WHERE field1 IN ('" .implode("', '", $_POST['checkbox']) . "') ";