Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: users online

  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts

    users online

    PHP Code:
    <?php
    session_start
    ();
    $session session_id();
    $time time();
    $time_check $time 600// 10 minutes

    $username "";
    $password "";
    $tbl_name "";

    mysql_connect("localhost"$username$password);
    mysql_select_db($tbl_name);
    $count mysql_num_rows(mysql_query("SELECT * FROM `user_online` WHERE `session` = '$session'"));

    if (
    $count=="0") {
        
    mysql_query("INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')");
    } else {
        
    mysql_query("UPDATE $tbl_name SET time='$time' WHERE session = '$session'");
    }

    $usersonline mysql_num_rows(mysql_query("SELECT * FROM $tbl_name"));

    mysql_query("DELETE FROM $tbl_name WHERE time < $time_check"); // Delete session over time limit
    mysql_close();
    ?>
    I keep getting mysql_num_rows(): supplied argument is not a valid MySQL.. Why?

  • #2
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    On which line?

  • #3
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Ok, I think I see your problem...

    PHP Code:
    <?php 
    session_start
    (); 
    $session session_id(); 
    $time time(); 
    $time_check $time 600// 10 minutes 

    $username ""
    $password ""
    $tbl_name ""

    mysql_connect("localhost"$username$password); 
    mysql_select_db($tbl_name); 
    $count mysql_num_rows(mysql_query("SELECT * FROM user_online WHERE user_online.session = '$session'")); 

    if (
    $count=="0") { 
        
    mysql_query("INSERT INTO $tbl_name(session, time)VALUES('$session', '$time')"); 
    } else { 
        
    mysql_query("UPDATE $tbl_name SET time='$time' WHERE session = '$session'"); 


    $usersonline mysql_num_rows(mysql_query("SELECT * FROM $tbl_name")); 

    mysql_query("DELETE FROM $tbl_name WHERE time < $time_check"); // Delete session over time limit 
    mysql_close(); 
    ?>
    Try that...

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I see an issue with this. You have this
    PHP Code:
    $tbl_name ""
    but then you use it here
    PHP Code:
    mysql_select_db($tbl_name); 
    Your $tbl_name is NOT your database name. You then use this here
    PHP Code:
    INSERT INTO $tbl_name(sessiontime)VALUES('$session''$time'
    So now $tbl_name has become an actual table and not a database. You can't insert directly into a database like that. You need to have database that has tables (this is where you insert, update, and delete from). I suspect your queries are erroring out but you aren't checking for any errors.
    PHP Code:
    <?php
    session_start
    ();
    $session session_id();
    $time time();
    $time_check $time 600// 10 minutes

    $username "";
    $password "";
    $tbl_name "";
    $db_name "";

    mysql_connect("localhost"$username$password);
    mysql_select_db($db_name);
    $result mysql_query("SELECT * FROM $tbl_name WHERE `session` = '$session'") or die(mysql_error());
    $count mysql_num_rows($result);

    if (
    $count==0) {
        
    mysql_query("INSERT INTO $tbl_name(session, time) VALUES ('$session', '$time')") or die(mysql_error());
    } else {
        
    mysql_query("UPDATE $tbl_name SET time='$time' WHERE session = '$session'") or die(mysql_error());
    }
    $result2 mysql_query("SELECT * FROM $tbl_name") or die(mysql_error());
    $usersonline mysql_num_rows($result2);

    mysql_query("DELETE FROM $tbl_name WHERE time < $time_check") or die(mysql_error()); // Delete session over time limit
    mysql_close();
    ?>
    Update $db_name, and try that. Let us know if you get any errors.
    Last edited by _Aerospace_Eng_; 08-30-2009 at 09:55 PM.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Blatch (08-30-2009)

  • #5
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    Ah, I didn't see that. Silly me.

  • #6
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Ahhh! Thank you

    How poorly coded was this?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •