I have three tables: unitpost, file, and postfile with postfile being the table that links files to a particular post.
I have created a script that uploads the files and posts however I need to populate the postfile table with both the unitpostID and fileID, however once the file is uploaded, the ID is chosen at random. How can I then populate the postfile table with the fileID that was just uploaded?
Hope this made sense!!
Any help appreciated.
使用LAST_INSERT_ID()
获取上一次插入操作的ID。
Use AUTOINCREMENT
for the primary keys, thus the IDs won't be random, and you will be able to use them either from MySQL or from PHP.
Afterwards use mysqli_insert_id()
(or PDO::lastInsertId
if you use PDO) from php to get the last insert id, or, as @Nelson stated, the MySQL function directly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.