Useronline mySQL/PHP help

http://www.sublogicmusic.com/

Currently only shows 6 people online at a time, i can change that later, but that is not my problem right now…
my problem is with the Usersonline part…

Im using mySQL to store users online from there IP and also a $name that goes to that IP

i pull the # of usersonline from the DISTINCT IPs and the different names from the DISTINCT name…

I have my flash code set up to send and recieve the info to the mySQL every 2 seconds, and delete if a user has been gone (timeout of 10sec)

My problem… (sometimes it works, sometimes it doesnt) inside the code, it keeps not connecting and not INSERTING the new information, so the old info times out and shows like the user signed off… is there some limit to connections per minute or hour??

Or can i keep a constant connection to mySQL and never close it(until flash file closes), but then there are more than one connections at the same time, is that possible?

any help would be MUCH APPRECIATED!!

Thanks - Solo

::edit:: should this be in a diff forum? server-side scripting ?

Accually i dont think its the conenction, it connects fine… the problem is in the INSERT, 1/2 the time it returns an error saying it didnt insert…

Check the syntax of your SQL query…it sounds like something in there might be causing your troubles.

mysql_connect($server, $db_user, $db_pass); 

$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$REMOTE_ADDR','$name','$PHP_SELF')"); 
if(!($insert)) { 
print "Useronline Insert Failed > "; 
} 

should be right… it works sometimes, but sometimes it doesnt, which causes it to show like the person signs off the site, then back on after awhile…

Ok well we’ll add in a tiny bit of code to check everything is working.
This is your original code…


$insert = mysql_db_query($database, "INSERT INTO useronline VALUES
('$timestamp','$REMOTE_ADDR','$name','$PHP_SELF')"); 

Instead, use this…


$insert = mysql_db_query($database, "INSERT INTO useronline (time, ip, name, page) VALUES
('$timestamp','$REMOTE_ADDR','$name','$PHP_SELF')") or die(mysql_error());

What I did was add the names of the database columns you want to enter data into. This has to match up with the values or you’ll get an error.

For example
name age phone
row1 billybob 25 555-423
row2 cleatus 22 911
row3 Jesus 2004 1800 Heven

To add billy bob into the database we would use this


$insert = mysql_db_query("INSERT INTO usersonline(name, age, phone) VALUES ('billybob', '25', '555-423')");
//So basically the values need to match the columns specified

The other thing I added was


or die(mysql_error());

The die function is executed on the event of a syntax error. Inside the brackets there is "mysql_error())"
This will print out any error in your mysql query.

If an error comes up, let me know and we’ll take it from there :slight_smile:

Cheers

i tried refreshing the php file like a million times one after another…
Sometimes it worked, sometimes i got a “Duplicate entry ‘1076099238’ for key 1” a few times…(number changes obvisouly)
then i checked it using the chat… looks like its doing the same thing…
is there a way i can still insert, but have php not care if its a duplicate entry?

Its like the different people online’s INSERT are competeing for the timestamp spot, cause there can be only one of each second…

I think i figured it out… in mySQL the first key was the timestamp, not allowing it to be a duplicate key… so i will just add a random gen number to the first key so thats primary, and then the timestamp can have duplicates… thanks for your help!!