Personally, I would use the built in
LAST_INSERT_ID()
function. [
^] This will return the most recently inserted Id within the scope of the connection.
In doing so, you will need to get your hierarchy of table dependencies correct. From the look of it, the sequence of inserts should go like this:
Insert into Projects (your values)
SET @last_id_from_insert = LAST_INSERT_ID();
Insert into Objectives (idProject)
Values (@last_id_from_insert)
SET @last_id_from_insert = LAST_INSERT_ID();
Insert into Results(idObjective)
Values (@last_id_from_insert)
SET @last_id_from_insert = LAST_INSERT_ID();
Insert into Activities(idResult)
Values (@last_id_from_insert)
As Dileep says, it would be good practice to do this within a stored procedure so that the connection scope is the same for each insert and retrieval of the latest Id.
Hope that helps.