I created a simple function that needs to display some information.
Some of this information comes from the database.
But, the database handler is not recognized within this function, therefor, I get the following errors:
Notice: Undefined variable: db in censored\controller\edit_mails.php on line 82
Fatal error: Call to a member function get_results() on null in censored\controller\edit_mails.php on line 82
I'm using the ezSQL database handler
The function:
function MessageSelector() {
$emails = $db->get_results("SELECT * FROM settings_emails WHERE cat = '$edit_type'" );
if(empty($emails)) {
//There are no messages to select
}
else {
//Create an option for each message
foreach ($emails as $email):
echo "<option value=\"", $email->title , "\" onclick=\"location.href='edit_emails.php?x=", $edit_type , "&mail=",$email->id,"';\">", $email->title , "</option>";
endforeach;
";}
}
Database Handler:
require_once ADMIN_DB_DIR . '/ez_sql_core.php';
require_once ADMIN_DB_DIR . '/ez_sql_mysql.php';
global $db;
$db = new ezSQL_mysql($dbuser, $dbpassword, $dbname, $dbhost);