What function in PHP can be used to obtain the ID of the last inserted record in a database table?

To obtain the ID of the last inserted record in a database table in PHP, you can use the mysqli_insert_id() function. This function returns the auto-generated ID that was inserted in the last query. You can call this function after executing an INSERT query to retrieve the ID of the inserted record.

// Execute your INSERT query here

// Get the ID of the last inserted record
$last_inserted_id = mysqli_insert_id($connection);

// Use $last_inserted_id as needed