Two inserts in PHP/MySQL using LAST_INSERT_ID() and rows from another table

前端 未结 3 1414
耶瑟儿~
耶瑟儿~ 2021-01-16 06:51

I am working on an events calendar using PHP and MySQL (V5.1) where the admin would add an event, and then an attendance list for that event would be created as well. I have

3条回答
  •  猫巷女王i
    2021-01-16 07:40

    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.

提交回复
热议问题