Question: how can I make sure that when uploading a new photo, the old one (from the database and the server) is deleted?
Answer 1, authority 100%
Delete the file via unlink and make UPDATE entries in the database:
unlink("file.gif"); $Query = "UPDATE `table` SET avatar='..' WHERE .. ";
Answer 2, authority 50%
You need to delete the old one, then load the new one and update the name in the database.
In general, formulate the question more clearly to get a more detailed answer.
By the way, lingwrote it right, formulate the problem and you will get an adequate answer.
It’s somehow unclear if you mean only the database or the database and the file system.