I am trying to get auto increment ID from the last query and update the same row. Also I would like to keep everything in the transaction and throw user friendly error if something goes wrong. Could you please help?
$parentSQL = "INSERT INTO TABLE1(test1, test2) VALUES ('" .$test1. "', '" .$test2. "')";
$result = mysql_query($parentSQL) or die(mysql_error());
$newId = MySql_Insert_Id();
$val = "MU".$newId;
$updateSQL = "UPDATE TABLE1 SET test3 = '" .$val. "' WHERE id= ".$newId." ";
$updateResult = mysql_query($updateSQL) or die(mysql_error());
$childSQL = "INSERT INTO TABLE2(testId, testCol) VALUES (" .$newId. ", '" .$testCol. "')";
$childResult = mysql_query($childSQL) or die(mysql_error());
This is just a suggestion, but why don’t you try using stored procedures instead?
In MySQL
In PHP, and using PDO to utilize prepared statements: