Alright, so here is a look at my PHP function. I can confirm I AM connected to the database, as I can make updates to it with mysqli_query functions directly in the file.
<?php
function username_from_id($id) {
$id = mysqli_real_escape_string($id);
$query = mysqli_query($d,"SELECT `username` FROM `users` WHERE `id` = '$id'");
$result = mysqli_fetch_array($query);
$res = $result['username'];
return $res;
}
?>
The purpose of the function is to select the username of a user if their ID equals what is put into the query, then return it. In the file, it looks like this
<?php
include 'file_where_function_is.php';
$id = '1';
echo username_from_id($id);
?>
Nothing shows up. Any ideas?
error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);if you're not already doing so.globalkeyword.$das a function argument 2) omit$dand themysqli_query()will use last used connection (which I find a great example of OOP fail in PHP) UPDATE: actually it has to be checked, as documentation describe that behavior formysql_query()but there's nothing like that aboutmysqli_query().$d