So on my web page i have a database connection setup. Once a user posts a comment on the web page it adds the comment to the database and a column in the database called ID gets incremented by 1. This ID serves as the primary key for the each row in the database. So when the user wants to remove a comment it checks the database for the comment that has matching primary key.
My current solution is this.
add the comment to the database
the database adds the ID
get the ID from the database
store it together with the comment in an array
When a user clicks delete comment check if the comment ID matches the ID in the database.
My problem with this is that it feels weird calling the database to add the comment and then call the database again to get the comment ID.
Is there any better solution to this?