Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:49:18+00:00 2026-06-17T05:49:18+00:00

i created a php code to show at admin who is online on website

  • 0

i created a php code to show at admin who is online on website and store the ip of users connected at website and delete from database when user is no longer on website after 10 min.its work but its show me this error and i dont know where i make wrong. somebody can help me with this thing?

the error is:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a7078942/public_html/online.php on line 17

and here is my code:

<?php

require "connect.php";
require "functions.php";

// We don't want web bots scewing our stats:
if(is_bot()) die();



$stringIp = $_SERVER['REMOTE_ADDR'];
$intIp = ip2long($stringIp);

// Checking wheter the visitor is already marked as being online:
$inDB = mysql_query("SELECT 1 FROM tz_who_is_online WHERE ip=".$stringIp);

if(!mysql_num_rows($inDB))
{
    // This user is not in the database, so we must fetch
    // the geoip data and insert it into the online table:

    if($_COOKIE['geoData'])
    {
        // A "geoData" cookie has been previously set by the script, so we will use it

        // Always escape any user input, including cookies:\
        list($city,$countryName,$countryAbbrev) = explode('|',mysql_real_escape_string(strip_tags($_COOKIE['geoData'])));
    }
    else
    {
        // Making an API call to Hostip:

        $xml = file_get_contents('http://api.hostip.info/?ip='.$stringIp);

        $city = get_tag('gml:name',$xml);
        $city = $city[1];

        $countryName = get_tag('countryName',$xml);
        $countryName = $countryName[0];

        $countryAbbrev = get_tag('countryAbbrev',$xml);
        $countryAbbrev = $countryAbbrev[0];

        // Setting a cookie with the data, which is set to expire in a month:
        setcookie('geoData',$city.'|'.$countryName.'|'.$countryAbbrev, time()+60*60*24*30,'/');
    }

    $countryName = str_replace('(Unknown Country?)','UNKNOWN',$countryName);

    // In case the Hostip API fails:

    if (!$countryName)
    {
        $countryName='UNKNOWN';
        $countryAbbrev='XX';
        $city='(Unknown City?)';
    }
    mysql_query("   INSERT INTO tz_who_is_online (ip,city,country,countrycode)
                    VALUES('".$stringIp."','".$city."','".$countryName."','".$countryAbbrev."')");
}
else
{
    // If the visitor is already online, just update the dt value of the row:
    mysql_query("UPDATE tz_who_is_online SET dt=NOW() WHERE ip='".$stringIp."'");
}

// Removing entries not updated in the last 10 minutes:
mysql_query("DELETE FROM tz_who_is_online WHERE dt<SUBTIME(NOW(),'0 0:10:0')");

// Counting all the online visitors:
list($totalOnline) = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM tz_who_is_online"));

// Outputting the number as plain text:
echo $totalOnline;

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:49:19+00:00Added an answer on June 17, 2026 at 5:49 am

    I think the problem may solve by this change:

    $inDB = mysql_query("SELECT 1 FROM tz_who_is_online WHERE ip='".$stringIp."'");
    

    But if this error occurs again please change the line :

    $inDB = mysql_query("SELECT 1 FROM tz_who_is_online WHERE ip=".$stringIp);
    

    to :

    $inDB = mysql_query("SELECT 1 FROM tz_who_is_online WHERE ip=".$stringIp) or die("Error: ". mysql_error(). " with query ". $query);
    

    to see whats the error make this problem and put the error in comment.

    notice: its better ask these question in stackoverflow instead of serverfault

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm migrating code from Symfony1.0 to Symfony 1.4. Created a admin module called: mymodel
I have created a PHP code to echo the following div <div id=main_catsel> <select
I am trying to debug the user object created by writing ruby code like
I have a user login system for a website set up with PHP and
This is my first time creating php/mysql code from scratch and Im a little
I'm creating quick web app that needs to send a php-created message from within
I've created a simple php messaging system for users to send and receive messages
I have following code created dynamically with php. What I want to do is
I have this php code. As you can see i query a mysql database
I have created a php page that displays some records from my db. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.