its very tricky part...

why you want to have the database value set to 1?? that is very poor coding..

you should have some function that does that update. so that needs to be altered with the session values. session can created with expiry time. so it will get expired soon you closed the window.

contact me, if you need more assistance to resolve the issue.