whiteboikyle Posted April 22, 2009 Share Posted April 22, 2009 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/ Share on other sites More sharing options...
Maq Posted April 22, 2009 Share Posted April 22, 2009 }; You have an extra ';' here. Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-816892 Share on other sites More sharing options...
whiteboikyle Posted April 22, 2009 Author Share Posted April 22, 2009 Fix that but still same error. Btw i do that because of C++ coding.. That is required in C++ Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-816928 Share on other sites More sharing options...
premiso Posted April 22, 2009 Share Posted April 22, 2009 Are you including the class before you try and run the query in main.php? Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-816942 Share on other sites More sharing options...
whiteboikyle Posted April 23, 2009 Author Share Posted April 23, 2009 i included Config.php like i said. and at the bottom of config.php i have the declaration Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-817073 Share on other sites More sharing options...
xtopolis Posted April 23, 2009 Share Posted April 23, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-817083 Share on other sites More sharing options...
whiteboikyle Posted April 23, 2009 Author Share Posted April 23, 2009 I found the problem.. i had <? include("./config.php"); ?> and it wasn't finding the config file because "short tags" dont work. Even tho i have them enabled?? Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-817732 Share on other sites More sharing options...
Axeia Posted April 23, 2009 Share Posted April 23, 2009 Even if they are enabled, avoid them.. as your next host might not have them enabled (and not offer the option to do so) Quote Link to comment https://forums.phpfreaks.com/topic/155265-solved-undefined-variable/#findComment-817740 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.