Is it possible to get the insert_id of the previous two queries? I am able to get the last one, but would like the previous two. In the below example, once the form in processed, I would like to add a new role to the address table, new row to the role table then add a row to the customers using the id's from the queries inserted in the previous two queries. Is this at all possible.
if(isset($_POST["submit"])) :
$username = $_POST["username"];
$password = $_POST["password"];
$role = $_POST["role"];
$permission1 = intval($_POST["permission1"]);
$permission2 = intval($_POST["permission2"]);
$city = $_POST["city"];
$state = $_POST["state"];
mysqli_autocommit($connection,FALSE);
mysqli_query($connection,"INSERT INTO Address(city, state) VALUES('{$city}', '{$state}')");
mysqli_query($connection,"INSERT INTO Roles(roleName, permission1, permission2) VALUES('{$role}', '{$permission1}', '{$permission2}')");
mysqli_query($connection,"INSERT INTO Customers(username, password, roleId, addressId) VALUES ('{$username}', '{$password}'," . mysqli_insert_id($connection) . " , " . mysqli_insert_id($connection) . ")");
if(mysqli_error($connection)):
echo mysqli_error($connection);
endif;
mysqli_commit($connection);
endif;
The mysqli_insert_id($connection)
in the last query will pull the Id from the Roles
insert twice. Any way to get it to grab the two Id vals from the first two queries?