Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. mysql_query error

mysql_query error

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
databasehelpphpmysqlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    komanche
    wrote on last edited by
    #1

    Hello all. Am having a major problem with my code.I cant find an error in the code but i keep getting this messages "Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 223 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 251 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 194 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 195 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 261 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203" and the php code is

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

    require\_once("constants.php");
    
    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;
    		
    		if(TRACK\_VISITORS)
    		{
    			//calculate number of users at site
    			$this->calcNumActiveUsers();
    			
    			//calculate number of guests at site
    			$this->calcNumActiveGuests();
    		}
    	}
    	//confirm users pass
    	function confirmUserpass($username, $password)
    	{
    		//add slashes if necessary
    		if(!get\_magic\_quotes\_gpc())
    		{
    			$username =
    
    G 1 Reply Last reply
    0
    • K komanche

      Hello all. Am having a major problem with my code.I cant find an error in the code but i keep getting this messages "Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 223 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 251 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 194 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 195 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 261 Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 202 Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\xampp\htdocs\nicks\includes\database.php on line 203" and the php code is

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

      require\_once("constants.php");
      
      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;
      		
      		if(TRACK\_VISITORS)
      		{
      			//calculate number of users at site
      			$this->calcNumActiveUsers();
      			
      			//calculate number of guests at site
      			$this->calcNumActiveGuests();
      		}
      	}
      	//confirm users pass
      	function confirmUserpass($username, $password)
      	{
      		//add slashes if necessary
      		if(!get\_magic\_quotes\_gpc())
      		{
      			$username =
      
      G Offline
      G Offline
      Gerben Jongerius
      wrote on last edited by
      #2

      I can't be 100% sure but it sounds like the constructor method is never actually called. I believe this because $this->connection is null when passed to the mysql_query method. The only reason I can think of is if the constructor is not called, if it had been and failed to initialize you would get an invalid resource exception. Try renaming it to:

      function __construct()
      {
      // your previous constructor code
      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups