Download to see users online.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aussieincanada
Forum Newbie
Posts: 4
Joined: Wed Jan 06, 2010 12:28 am

Download to see users online.

Post by aussieincanada »

Hello moderators...this is my first post..I have done a lot of reading but can not find the answer.

I have made a mysql database and would like to be able to see who is online using php.

I have what I think is the right script but get a white screen, so apparently there is a mistake in it somewhere.

I am a newbie to php...and need assistance please. :crazy:

The database has a field active users, and I know my config file is okay, everything else...register, login etc work perfectly

The offending script is here.

Code: Select all

 
<?php
session_start();
include('config.php');
$conn = mysql_connect($server,$dbusername,$dbpassword)or die (mysql_error());
$db = mysql_select_db($db_name,$conn) or die (mysql_error());
$sql = "SELECT * FROM active_users";
$result = mysql_query($sql,$conn);
while($sql = mysql_fetch_object($result)){
   $_uname = $sql -> username;
 
   echo $_uname;
   echo "<br>";
   }
?>
 
Can you please find the fault.

Thanks in advance
aussieincanada
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Download to see users online.

Post by Griven »

aussieincanada
Forum Newbie
Posts: 4
Joined: Wed Jan 06, 2010 12:28 am

Re: Download to see users online.

Post by aussieincanada »

Thanks Griven,

But I am trying to fix this code for my own education.

i have read and reread a heap of stuff, but am stumped here:

May be my age...over 70 :lol:

ausiencanada
aussieincanada
Forum Newbie
Posts: 4
Joined: Wed Jan 06, 2010 12:28 am

Re: Download to see users online.

Post by aussieincanada »

Has anyone any idea what the fault is in this script to give me a white screen? :crazy:
abushahin
Forum Commoner
Posts: 42
Joined: Wed Nov 25, 2009 12:35 pm
Location: london

Re: Download to see users online.

Post by abushahin »

Hey I can't see any obvious faults maybe cos I'm looking at it from my bb, but would u consider adding a or die to the select query just to be sure that the query is working.
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Download to see users online.

Post by Griven »

The reason your script is failing is because you are not putting anything into the database to be read. For you to pull information from the database, there must be something there.
aussieincanada
Forum Newbie
Posts: 4
Joined: Wed Jan 06, 2010 12:28 am

Re: Download to see users online.

Post by aussieincanada »

Thanks for your replies.

Griven I think I know what you are saying.

Just because the fields are on the database , unless someone is actually online there is nothing to view...is that correct?

aussieincanada
Griven
Forum Contributor
Posts: 165
Joined: Sat May 09, 2009 8:23 pm

Re: Download to see users online.

Post by Griven »

Almost...

If you want to see who is logged in using your database, you'll have to first PUT information into the database WHEN someone logs in with their username and password.

I gave you the link in my previous post, not because I wanted to give an obnoxiously short reply, but because it illustrates the point perfectly.
Post Reply