Jump to content

delete row from mysql on logout


CBaZ

Recommended Posts

i get a blank screen from this any ideas?

 

<?
session_start();
if ($yes) {

include ("password/dbinfo.php")

define("SESSION_LENGTH", 60); 

$sConn = @mysql_connect($dbServer, $dbUser, $dbPass) 
or die("Couldnt connect to database"); 

$dbConn = @mysql_select_db($dbName, $sConn) 
or die("Couldnt select database $dbName"); 

$timeMax = time() - (60 * SESSION_LENGTH);
{ 
// Delete a record for this user 
$delete = mysql_query("DELETE FROM usersOnline WHERE dateAdded<$timeMax") or die("Unable remove timed outusers");
$d = mysql_query($delete);
} 
session_destroy();  
}
?>
</code>

Link to comment
Share on other sites

I think it is good that you get a blank screen since the only output happens if there is an error.

 

However, there should be an error there because you are setting $delete to a result set and then using it in mysql_query() which expects a string. Simply removing the line: $d = mysql_query($delete); would fix that.

Link to comment
Share on other sites

<?php 
include ("password/dbinfo.php")
$sConn = @mysql_connect($dbServer, $dbUser, $dbPass) 
or die("Couldnt connect to database"); 

$dbConn = @mysql_select_db($dbName, $sConn) 
or die("Couldnt select database $dbName"); 
// Delete a record for this user 
$timeMax = time() - (60 * SESSION_LENGTH);
$userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"]; 
$result = mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax' and userIP = '$userIP'"); 
mysql_query($result);

$q = mysql_query("DELETE FROM usersOnline WHERE unix_timestamp(dateAdded) >= '$timeMax' and username = '$username'");
     mysql_query($q);
?>

Link to comment
Share on other sites

this is how I get it to insert just doesn't delete and username here is working so I am not sure whats going on for the delete.

<code>

<?php

 

include("dbinfo.php");

 

 

global $HTTP_SERVER_VARS;

 

 

// Set length of session to twenty minutes

define("SESSION_LENGTH", 20);

 

$userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"];

 

$sConn = @mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldnt connect to database");

 

$dbConn = @mysql_select_db($dbName, $sConn)

or die("Couldnt select database $dbName");

 

$timeMax = time() - (60 * "SESSION_LENGTH");

$result = mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax' and userIP = '$userIP'");

 

$recordExists = mysql_result($result, 0, 0) > 0 ? true : false;

if(!$recordExists) $usersonline = mysql_num_rows($recordExists);

{

// Add a record for this user

@mysql_query("INSERT INTO usersOnline(userIP, username, permission, user_id) values ('$userIP', '$_SESSION[username]', '$_SESSION[permission]', '$_SESSION[id]')"); 

@mysql_query("DELETE FROM usersOnline WHERE dateAdded < $timeMax");

mysql_close();

return $usersonline;

}

?> </code>

Link to comment
Share on other sites

@ removed :) as far as the deleting row goes do you know whats missing here?

<?php

 

include("dbinfo.php");

 

 

global $HTTP_SERVER_VARS;

 

 

// Set length of session to twenty minutes

define("SESSION_LENGTH", 20);

 

$userIP = $HTTP_SERVER_VARS["REMOTE_ADDR"];

 

$sConn = mysql_connect($dbServer, $dbUser, $dbPass)

or die("Couldnt connect to database");

 

$dbConn = mysql_select_db($dbName, $sConn)

or die("Couldnt select database $dbName");

 

$timeMax = time() - (60 * "SESSION_LENGTH");

$result = mysql_query("select count(*) from usersOnline where unix_timestamp(dateAdded) >= '$timeMax' and userIP = '$userIP'");

 

$recordExists = mysql_result($result, 0, 0) > 0 ? true : false;

if(!$recordExists) $usersonline = mysql_num_rows($recordExists);

{

// Add a record for this user

mysql_query("INSERT INTO usersOnline(userIP, username, permission, user_id) values ('$userIP', '$_SESSION[username]', '$_SESSION[permission]', '$_SESSION[id]')"); 

mysql_query("DELETE FROM usersOnline WHERE dateAdded < $timeMax");

mysql_close();

return $usersonline;

}

?>

Link to comment
Share on other sites

I'm not sure where your learning php from but this code is terrible. Firstly the global keyword has no benfit when called within the global scope. Secondly, your attempting to make the already global (and by the way depricated) $HTTP_SERVER_VARS array global, why? It already is.

 

Thirdly, your using depricated arrays (eg; $HTTP_SERVER_VARS) all through the script.

 

Fourth, your define a constant...

 

define("SESSION_LENGTH", 20);

 

but never use it. Instead you attempt to multiply the string "SESSION_LENGTH" by 60.

 

$timeMax = time() - (60 * "SESSION_LENGTH");

 

Should be....

 

$timeMax = time() - (60 * SESSION_LENGTH);

 

Next, you execute an sql SELECT statement then go ahead and assume it works without any form of error handling.

 

Next, I don't even understand how you think this line works in the context of this script...

 

if(!$recordExists) $usersonline = mysql_num_rows($recordExists);

 

Next you supress any error messages that might help you find the problem by placing the error supressor in front of calls to mysql_query().

 

And finally, you use the return keyword which is of no benifit outside a function.

 

First suggestions, remove all error supressors and add the following to the top of all your scripts.

 

<?php error_reporting(E_ALL) ; ini_set('display_errors','1'); ?>

 

Next suggestion, find a better reference for learning php. Whatever your using is out of date and well out of touch.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.