I'm trying to use a simple query though a function, it is not working and I have no clue why.
This code woks perfectly outside a function:
$mysqli = new mysqli($db_hostname, $db_username, $db_password, $db_database);
$NEWUSER = "jack";
$query = $mysqli->query("SELECT user_name FROM Users WHERE user_name = '$NEWUSER'");
$result = implode("",$query->fetch_assoc());
echo $result;
However when I place it in a function it ceases to work!?
$mysqli = new mysqli($db_hostname, $db_username, $db_password, $db_database);
$NEWUSER = "jack";
someFunction();
function someFunction() {
$query = $mysqli->query("SELECT user_name FROM Users WHERE user_name = '$NEWUSER'");
$result = implode("",$query->fetch_assoc());
echo $result;
}
I'm woking on upgrading my PHP 5.5 site to 7.2 and I don't understand what am I doing wrong because this worked just fine previously, thanks.