Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,059 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,558 people online right now. Registration is fast and FREE... Join Now!




On Close

 
Reply to this topicStart new topic

On Close

fyrestorm
13 Nov, 2002 - 01:52 PM
Post #1

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
when a person closes a page is there a way to run a script that they don't see that will delete information from a db?
User is offlineProfile CardPM
+Quote Post

jaybee
RE: On Close
18 Nov, 2002 - 03:33 AM
Post #2

New D.I.C Head
*

Joined: 30 Sep, 2002
Posts: 9

you could call a javascript function that opens an interstitial window containing your delete.php which immediately closes itself - will be unnoticeable for most...eg:
CODE

function openWin() {
remote = window.open("delete.php?id=<? =$id>");
}

//body tag
<body onClose="openWin();">

then delete.php could be something like:
CODE

//php
$id = $_GET["id"];
$c = ..._connect($hostName,$username);
..._select_db($databaseName,$c);
$q = "DELETE FROM table WHERE ID=".$id;
$r = ..._query($q,$c);
//body tag
<body onLoad="self.close();">

altho' a file which deletes records from your db according to whatever's passed to it in the querystring has some obvious worries... huh.gif just an idea...
User is offlineProfile CardPM
+Quote Post

Spider
RE: On Close
18 Nov, 2002 - 11:17 AM
Post #3

Arachnid
****

Joined: 10 Jul, 2002
Posts: 769


My Contributions
nice idea, but I believe all browsers default to popping up a warning message when a window tries to close itself. So the popup would appear and then a warning box would appear saying "this window is trying to close itself"

probably not a great solution.

what exactly are you wanting to remove from a database every time someone leaves the page? I can't think of a situation where that would be necessary...
User is offlineProfile CardPM
+Quote Post

MathewS
RE: On Close
18 Nov, 2002 - 12:57 PM
Post #4

D.I.C Regular
***

Joined: 14 May, 2002
Posts: 252



Thanked: 1 times
Dream Kudos: 1
My Contributions
why not but the delete code at the bottom of the page that way theres no need for a pop up. e.g.
CODE

<?
//normal page code
?>
HTML here
<?
//delete code here
?>

User is offlineProfile CardPM
+Quote Post

Quik
RE: On Close
18 Nov, 2002 - 01:01 PM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2001
Posts: 3,750



Thanked: 1 times
My Contributions
uhh.. why not store the variables in a session? or cookie even?
User is offlineProfile CardPM
+Quote Post

Quik
RE: On Close
18 Nov, 2002 - 01:02 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2001
Posts: 3,750



Thanked: 1 times
My Contributions
II think it would be a better idea to explain what needs to erase information onclose...
User is offlineProfile CardPM
+Quote Post

jaybee
RE: On Close
19 Nov, 2002 - 06:56 AM
Post #7

New D.I.C Head
*

Joined: 30 Sep, 2002
Posts: 9

QUOTE
nice idea, but I believe all browsers default to popping up a warning message when a window tries to close itself.


not if the window is one you opened yourself using javascript tongue.gif ph34r.gif
User is offlineProfile CardPM
+Quote Post

fyrestorm
RE: On Close
20 Nov, 2002 - 07:27 PM
Post #8

D.I.C Lover
Group Icon

Joined: 4 Apr, 2002
Posts: 3,103



Thanked: 2 times
Dream Kudos: 228
My Contributions
i actually figured that i could just put the script piece that i needed at the bottom of the page



i believe someone may have suggested that.....
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:15PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month