Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522752
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522758
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522829
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-522898
Share on other sites

<?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

Link to comment
https://forums.phpfreaks.com/topic/102127-will-not-add-to-db/#findComment-524779
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.