Hi all am having problems with my login forms. I have written the code and has no errors, but when I run it from my browser i get
"Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 269"
I have a "MySQL Table with Members where there are fields 'ID, username,password, firstname'"
I have several pages such as "Session, process, database, form, constants";
part of the code is:

    /** this is the database connections specification files
        can only be changed by an administrator 
    //connect to database


    class MySQLDB
        var $connection;                //the mysql database connection
        var $num_active_user;           //number of active users viewing site
        var $num_active_guests;         //number of guests viewing site
        var $num_members;               //number of signed users

        //class constructor
        function MySLQDB()

            $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die (mysql_error());
            mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

            //only query database to find out number of members when getnummembers() is called for the first time, until then
            //default value is set
            $this->num_members = -1;

                //calculate number of users at site

                //calculate number of guests at site

    function calcNumActiveUsers()
        $q = "SELECT * FROM active_users";
        $result = mysql_query($q, $this->connection);
        $this->num_active_users = mysql_num_rows($result);

    function calcNumActiveGuests()
        $q = "SELECT * FROM active_guests";
        $result = mysql_query($q, $this->connection);
        $this->num_active_guests = mysql_num_rows($result);

    function addActiveUser($username, $time)
        $q = "UPDATE members SET timestamp = '$time' WHERE username = '$username'";
        mysql_query($q, $this->connection);

        if(!TRACK_VISITORS) return;
        $q = "REPLACE INTO active_users VALUES ('$username', '$time')";
        mysql_query($q, $this->connection);

please help I have been cracking my head

Edited by pyTony: fixed formating

7 Years
Discussion Span
Last Post by divyakrishnan

This error is being caused because of the failure of mysql query. It is due to the following resons
missing of single quotes for varchar & date
incorrect posted data because of white space,quotes etc.

It is better u display all the query statements before running.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.