I pondered on Simon Kariri's post and remembered postgre has similar functionality.
Then i checked out the postgre documentation
I found a simple solution to sort it out in 2 queries!
Haven't checked for MySQL since i'm using PgSQL
1 Insert to table 1 and get the primary key in ONE QUERY
PGresult* result = PGquery("INSERT INTO TABLE1 (table_1_id,some_column) VALUES (DEFAULT, 'value flani') RETURNING table_1_id");
2 Insert to table 2 using the returned result from the previous query
PGquery("INSERT INTO TABLE2 (table_2_id,some_other_column, table_1_id) VALUES (DEFAULT, 'value flani',"+ PQgetvalue(result, 0, 0) +")");
Fast and Simple! No programming overhead