I had the same issue. mysql_insert_id() or LAST_INSERT_ID() returned 0 when requested inside a PHP function with an INSERT query.
I sorted the issue by requesting the value of mysql_insert_id() from a separate PHP function called right after the function that INSERT query.