Hello all,
I have a PHP/Mysql program created by CodeCharge Studio has to submit two forms on one submit using Javascript, like:
function submitAll() {

form1 is to deal with the parent table which has an auto_increment id, called pid:
INSERT INTO parent_table VALUES('name1', 'address1');

After insertion to the parent table, I use mysql_insert_id() to get the latest id. I save it as a session variable $max_id.

from2 is to deal with the child table, which has its own primary key, called cid, all I wanna do is to save lastest pid to one of its columns.
INSERT INTO child_table (pid, item) VALUES($max_id, 'item1');

To ensure I can get the lastest id from parent_table, I even try to put " SELECT MAX(id) FROM parent_table " before INSERT to the child_table, and compared with the mysql_insert_id(). It works sometimes but sometimes not.

How can I get around of this problem? thanks.