A couple of important points. First, if you getting your last insert ID you should execute LOCK and UNLOCK queries first:
- LOCK TABLES
events
WRITE; - UNLOCK TABLES
Second, you can use the mysqli_insert_id() method to get the ID of the last insert. This means that you must have an AUTO_INCREMENT field in the table you are inserting.