Jump to content

Recommended Posts

hi, its the same script but different problem

 

<?php
//fill in some basic info
$server = "localhost";
$db_user = "";
$db_pass = "";
$database = "chrisrulez_usersonline";
$timeoutseconds = 300;

//get the time
$timestamp = time();
$timeout = $timestamp-$timeoutseconds;

//connect to database
mysql_connect($server, $db_user, $db_pass);

//insert the values
$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','{$_SERVER['REMOTE_ADDR']}','{$_SERVER['PHP_SELF']}')");
if(!($insert)) {
    print "Useronline Insert Failed > ";
}

//delete values when they leave
$delete = mysql_db_query($database, "DELETE FROM useronline WHERE $timestamp<$timeout");
if(!($delete)) {
   print "Useronline Delete Failed > ";
}

//grab the results
$result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='{$_SERVER['PHP_SELF']}'");
if(!($result)) {
   print "Useronline Select Error > ";
}

//number of rows = the number of people online
$user = mysql_num_rows($result);


//spit out the results
mysql_close();
if($user == 1) {
print("$user user online\n");
} else {
print("$user users online\n");
}
?>

 

//delete values when they leave

$delete = mysql_db_query($database, "DELETE FROM useronline WHERE $timestamp<$timeout");

if(!($delete)) {

print "Useronline Delete Failed > ";

 

^ that bit is causing the problem, i think.

 

with the problem the script shows:

 

Useronline Delete Failed > 1 user online

 

i would like it just to show:

 

1 user online

Link to comment
https://forums.phpfreaks.com/topic/51108-solved-php-users-online-script/
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.