CBaZ Posted July 1, 2008 Share Posted July 1, 2008 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> Quote Link to comment Share on other sites More sharing options...
lemmin Posted July 1, 2008 Share Posted July 1, 2008 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. Quote Link to comment Share on other sites More sharing options...
.josh Posted July 1, 2008 Share Posted July 1, 2008 My first guess is that your blank screen is due to you not having any output. My 2nd guess is that $yes isn't defined, at least, not in the code you've provided, so it'll always be false. Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 1, 2008 Author Share Posted July 1, 2008 <?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); ?> Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 1, 2008 Author Share Posted July 1, 2008 anyone see how I coud delete the rows with this setup? id username I wanna try and do it via username but its not working the way I have i at all. still blank page. Quote Link to comment Share on other sites More sharing options...
.josh Posted July 1, 2008 Share Posted July 1, 2008 that's because $username is not defined. Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 1, 2008 Author Share Posted July 1, 2008 http://www.kanenas.net/comments.php?y=05&m=10&entry=entry051012-071745 this how i get my users in to the database now I can not figure out how to get them out when a person logs out. Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Again, $username is not defined anywhere in your script. Start there. Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 2, 2008 Author Share Posted July 2, 2008 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> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted July 2, 2008 Share Posted July 2, 2008 please remove the @ it does nothing but supress errors Quote Link to comment Share on other sites More sharing options...
CBaZ Posted July 2, 2008 Author Share Posted July 2, 2008 @ 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; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 2, 2008 Share Posted July 2, 2008 Oh and ps: Please use tags when posting attempts at code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.