in reply to SELECT LAST_INSERT_ID does not work
The shown code could not be as such. It must have been distributed among different programs, else your query does not make sense. At least be self-consistent.