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
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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.