how can i update a table when a user close the page or exit from that page..................
If there's pending AJAX calls you can ask the user to stay on the page by listening for the onbeforeunload event. Ultimately the user can choose to interrupt whatever pending processing needs to be done, either by navigating away, closing the window, killing the browser process, experiencing a computer crash, etc. You application should be robust enough to handle these situations.
You can have some kind of periodic timer server-side, which resets for each request. If that timer passes the session lifetime, then the user is no longer active, and you can do whatever you need to do.
You can't (directly). You could however attempt to make a JavaScript unload event call (via Ajax) to the server which would then trigger the required MySQL activity.
However, you can't really rely on this happening reliably (not everyone has JavaScript installed, etc.)
What problem are you attempting to solve?