Page 1 of 1

Download to see users online.

Posted: Wed Jan 06, 2010 12:44 am
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

Re: Download to see users online.

Posted: Wed Jan 06, 2010 12:49 am
by Griven

Re: Download to see users online.

Posted: Wed Jan 06, 2010 1:01 am
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

Re: Download to see users online.

Posted: Wed Jan 06, 2010 3:46 pm
by aussieincanada
Has anyone any idea what the fault is in this script to give me a white screen? :crazy:

Re: Download to see users online.

Posted: Wed Jan 06, 2010 6:45 pm
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.

Re: Download to see users online.

Posted: Wed Jan 06, 2010 8:18 pm
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.

Re: Download to see users online.

Posted: Thu Jan 07, 2010 1:22 am
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

Re: Download to see users online.

Posted: Thu Jan 07, 2010 6:10 pm
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.