How can the mysql_insert_id() function be used to return the last inserted ID in the provided PHP code?

To return the last inserted ID in PHP, you can use the mysql_insert_id() function which retrieves the ID generated for an AUTO_INCREMENT column by the previous query. After executing an INSERT query, you can call mysql_insert_id() to get the ID of the last inserted row in the database.

// Execute your INSERT query here

$inserted_id = mysql_insert_id($connection); // $connection is your database connection variable

echo "Last inserted ID: " . $inserted_id;