hi all,
ok basically i need to run a line of MySQL code when the browser is ran to update a value in the database. I have found some forums which come up with solutions but they are in languages which i don't know e.g. ASP.
Is there a way of doing this in either PHP or JavaScript?
Thanks,
J
updae a database value when the browser is closed
Started by welton122, Nov 23 2010 02:21 PM
8 replies to this topic
#1
Posted 23 November 2010 - 02:21 PM
|
|
|
#3
Posted 23 November 2010 - 05:19 PM
Sounds like something you would want to happen on session end to mark in the database that a user is no longer active.
#4
Posted 23 November 2010 - 11:37 PM
WingedPanther has described exactly what i am after, does anyone know a way of accomplishing this? i heard rumors of using AJAX but im not sure?
#5
Posted 23 November 2010 - 11:52 PM
Yes, you could use Ajax to tell the database to set them offline when they close the window/tab. A simple JS method to perform this on most browsers is the following.
<html>
<title></title>
<head>
<script language="Javascript">
function doAjax()
{
alert('Example: You had exited');
}
</script>
</head>
<h1>Try to exit the browser.</h1>
<body onUnload="doAjax();">
</body>
</html>Of course replacing the alert() with the Ajax call to the PHP script of which will mark them offline.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#6
Posted 24 November 2010 - 04:52 AM
Thanks I believe that's what was looking for. Does anyone know the Ajax code to call a php page?
Thanks
Thanks
#7
Posted 02 December 2010 - 07:13 AM
hi,
okay basically i need a PHP script to run when a session ends. The script will update a value in the database. This script needs to be ran even if the user has closed the browser. Is there a way of doing this?
Many Thanks,
Jake
okay basically i need a PHP script to run when a session ends. The script will update a value in the database. This script needs to be ran even if the user has closed the browser. Is there a way of doing this?
Many Thanks,
Jake
#8
Posted 02 December 2010 - 07:18 AM
I would like to reffer you to another thread, with a similar request. Please view this :
http://forum.codecal...html#post282238
http://forum.codecal...html#post282238
#9
Posted 02 December 2010 - 09:16 AM
I had merged your threads, please do not create more than one thread on the same subject. It leaves out a lot of information of the previous one.
Your question about AJAX can be answered easily with a tutorial, as there is no special function required to be used with the example I had given before:
Ajax Tutorial - Form
Instead of my alert() , you will replace that simply with the javascript required to start the AJAX request. When you do that you will need to create a PHP page that accepts a request to update the database value, and tell AJAX to call 'updatedb.php?user=123&value=xxx' for example, updatedb.php handling those parameters.
Your question about AJAX can be answered easily with a tutorial, as there is no special function required to be used with the example I had given before:
Ajax Tutorial - Form
Instead of my alert() , you will replace that simply with the javascript required to start the AJAX request. When you do that you will need to create a PHP page that accepts a request to update the database value, and tell AJAX to call 'updatedb.php?user=123&value=xxx' for example, updatedb.php handling those parameters.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.


Sign In
Create Account


Back to top









