Jump to content

[SOLVED] Undefined variable?


whiteboikyle

Recommended Posts

Notice: Undefined variable: config in C:\wamp\www\clanphobia.net\main.php on line 21

 

Fatal error: Call to a member function query() on a non-object in C:\wamp\www\clanphobia.net\main.php on line 2

at line 15 is

$checkIA = $config->query("SELECT * FROM members WHERE username = '$username'");

 

but i have my config file as a Include which is

<?php
class MySQLDB
{
   var $connection;         //The MySQL database connection

   /* Class constructor */
   function MySQLDB(){
      /* Make connection to database */
      $this->connection = @mysql_connect("HOST", "USERNAME", "PASSWORD") or die(mysql_error());
      mysql_select_db("DATABASE", $this->connection) or die(mysql_error());
}
/**
    * query - Performs the given query on the database and
    * returns the result, which may be false, true or a
    * resource identifier.
    */
//Use this function as query("Query line of code");
   function query($query){
      return mysql_query($query, $this->connection);
   }
};

$config = new MySQLDB;
?>

Link to comment
https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/
Share on other sites

I do not get that error running a test script as such:

<?php
error_reporting(E_ALL);
class MySQLDB
{
   var $connection;         //The MySQL database connection

   /* Class constructor */
   function MySQLDB(){
      /* Make connection to database */
      $this->connection = @mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());
      mysql_select_db("xxx", $this->connection) or die(mysql_error());



}



/**
    * query - Performs the given query on the database and
    * returns the result, which may be false, true or a
    * resource identifier.
    */



//Use this function as query("Query line of code");
   function query($query){
      return mysql_query($query, $this->connection);
   }
};

$config = new MySQLDB;
$checkIA = $config->query("SELECT CURDATE()");
?>

PHP 5.2.9

(tested with my actual database)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.