mysql delete row when user exits
i am in a situation where i want the db to delete a row when the user exits the application. even in the middle of the application. how can it be done?
to be more specific, consider a survey of 10 questions. i am storing the user's selections in a DB. now suppose the user exits at the 5th question. i want to delete the user's records then and 开发者_如何学运维there. so that if the user wishes to start again. s/he can start afresh.
I think you need to rethink your design. You should start a new session each time the user starts the survey. Clean up abandoned answers on a scheduled basis.
Never depend on browser close to perform actions like this.
You need a watchdog function that is called regularly. It compares it's list of logged in users with the real list. When there is a conflict it performs the SQL operation you require.
精彩评论