after php code row 1 and 2, I got a notice and error message.
Notice: Undefined variable: dbc in …
Warning: mysqli_get_host_info()
expects parameter 1 to be mysqli, null given in …
connectdb();
echo mysqli_get_host_info($dbc);
Can you help me please to solve my notice & warning?
How can I make $dbc defined also for outher functions? I am working with error level -1 by the time being. please don’t tell not to display the notices as a solution. Unfortunately, I can’t understand the custom function variable passage issues. thanks.
function connectdb()
{
$dbc = mysqli_connect (db_host, db_user, db_password, db_name);
if (!$dbc)
{
$txt = mysqli_connect_errno().mysqli_connect_error();
db_connect_error_mail($txt);
unset ($txt);
die('error message.');
}
else
{
return $dbc;
}
}
You aren’t assigning the return value of connectdb() method anywhere. You want:
For clarity I have used a different variable name as the one you use in your function, because they are different variables, as they are defined in different scopes.