runnerjp Posted April 21, 2008 Share Posted April 21, 2008 hey guys i have got this code <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','function get_username','$_SESSION['user_id']')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $id = "user"; } else { $id = "users"; } ?> should show where users are ect username a ip who are on the site but all i get is a blank page... any reason why? Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/ Share on other sites More sharing options...
DarkWater Posted April 21, 2008 Share Posted April 21, 2008 hey guys i have got this code <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','function get_username','$_SESSION['user_id']')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $id = "user"; } else { $id = "users"; } ?> should show where users are ect username a ip who are on the site but all i get is a blank page... any reason why? You get a blank page because you have no output statements like echo() or anything. Oh. And see this part of your SQL statement? function get_username Do this: $uname = get_username(); $insert = mysql_query("Blah blah blah"); And put $uname in place of where you had function get_username. Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522752 Share on other sites More sharing options...
unidox Posted April 21, 2008 Share Posted April 21, 2008 Your only defining the query's, remove the var, and use if() to determine if it is going to delete or not. Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522753 Share on other sites More sharing options...
runnerjp Posted April 21, 2008 Author Share Posted April 21, 2008 ok i have got it to update timestamp and ip address and thats all still get blank page... i have done this <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; $username= get_username() //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, user_id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$username','$_SESSION['user_id']')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $ol_label = "user"; } else { $ol_label = "users"; } ?><?php echo "<b>$users</b> $ol_label"; ?> online Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522758 Share on other sites More sharing options...
runnerjp Posted April 21, 2008 Author Share Posted April 21, 2008 ? Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522797 Share on other sites More sharing options...
runnerjp Posted April 21, 2008 Author Share Posted April 21, 2008 <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; $username= get_username() //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, user_id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$username','".$_SESSION['user_id']."')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $ol_label = "user"; } else { $ol_label = "users"; } ?><?php echo "<b>$usersonline</b> $ol_label"; ?> online edited my "' errors lol but still no luck Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522829 Share on other sites More sharing options...
runnerjp Posted April 21, 2008 Author Share Posted April 21, 2008 Warning: Missing argument 1 for get_username(), called in /home/runningp/public_html/members/include/main.php on line 70 and defined in /home/runningp/public_html/functions.php on line 309 Error in who's online insert query! line 309 of function is just function get_username ( $id ) { global $db; $query = "SELECT `Username` FROM `" . DBPREFIX . "users` WHERE `ID` = " . $db->qstr ( $id ); if ( $db->RecordCount ( $query ) == 1 ) { $row = $db->getRow ( $query ); return $row->Username; } else { return FALSE; } } works fine usually :S also updated code is <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; $username= get_username(); //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, user_id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$username','".$_SESSION['user_id']."')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $ol_label = "user"; } else { $ol_label = "users"; } ?> <?php echo "<b>$usersonline</b> $ol_label"; ?> online Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522898 Share on other sites More sharing options...
sasa Posted April 21, 2008 Share Posted April 21, 2008 try $username= get_username($_SESSION['user_id']); Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522907 Share on other sites More sharing options...
runnerjp Posted April 21, 2008 Author Share Posted April 21, 2008 what would i need to echo to show how many users are online at that time>>> Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-523228 Share on other sites More sharing options...
runnerjp Posted April 22, 2008 Author Share Posted April 22, 2008 i have it mostly sorted but i have the porblem that it creats more then 1 row of data im my table like so how can i solve this so it only has 1 set of data for each user?? Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-523778 Share on other sites More sharing options...
runnerjp Posted April 22, 2008 Author Share Posted April 22, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-523883 Share on other sites More sharing options...
runnerjp Posted April 22, 2008 Author Share Posted April 22, 2008 can i do it so that if users is allready in db it just updates the field? Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-524342 Share on other sites More sharing options...
runnerjp Posted April 23, 2008 Author Share Posted April 23, 2008 <?php require_once '../settings.php'; $timestamp = time(); $timeout = $timestamp - 180; $username= get_username(); //Insert User $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, user_id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$username','".$_SESSION['user_id']."')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_useronline WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_useronline") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $ol_label = "user"; } else { $ol_label = "users"; } ?> <?php echo "<b>$usersonline</b> $ol_label"; ?> online i took this and replaced $insert = mysql_query("INSERT INTO $tbl_useronline (timestamp, ip, file, user, user_id) with REPLACE INTO but this only saves 1 bit of data... i want to save every ones last entry as well as showing whos currenlty online so i cn check up on people for security reasons Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-524779 Share on other sites More sharing options...
runnerjp Posted April 23, 2008 Author Share Posted April 23, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-524888 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.