INSERT INTO table_name (col1, col2,...) VALUES ('val1', 'val2'...);
If, at the point that you do the table1 insert, the database knows all the information that you want to insert into table2, then you could use a trigger to do this, or combine this into a query. If not, then you'd need to use multiple queries - i.e. do it in PHP. It depends on what the data is and where it's coming from for the second insert.
Ok, I see...the last insert id of the query is recorded even if it isn't logged in the result...$mysqli->insert_id
So suppose 3 users simultaneously posted their forms and my database has to enter them. I want to add a row corresponding to each newly created ID of table1 in table2. Is concurrency taken care of or will I have to do it in PHP manually, for incoming database write requests?
So this is unaffected by other queries that might be running on the server from other users.
That is if you have two separate requests to the script simultaneously they won't affect each others' LAST_INSERT_ID() (unless you're using a persistent connection perhaps).
The ID that was generated is maintained in the server on a per-connection basis
This will get you back the PRIMARY KEY value of the last row that you inserted, because it's per connection - each connection to the server will maintain it's own value for this. I've updated the answer to clarify this.
yes but what if in the interim (between queries in the process list) some other row has been inserted? Is there any way to write the insert query so that it outputs this?