thanks! actually I didn't realize you can use placeholders with quote identifiers. For some reason I thought they had to be used separately.
So I didn't fully comprehend my own code as some of it was borrowed. If I understand the code correctly, id will be equal to the new auto-increment id, which also means I can call that id from last_insert_id()? Also if it wasn't a duplicate, the last_insert_id() would also have the new key? So basically, with this I can always rely on last_insert_id() to give me the key?