tags:

views:

38

answers:

2

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.

A: 

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.

yosser
+2  A: 

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.

Jeremy Seekamp
I would even dare to say to store the survey progress in a session and save it in the database on finish
LukeP
Sure that's a good option as well
Jeremy Seekamp