0

I am trying to get a function to output on a page on my site.

All my functions are in functions.php, which I include in the head on all pages.

Here is an example function:

function get_username(){
    $userID = $_SESSION['user'];
    if($userID){
        $username = mysqli_query($dbconfig,"SELECT * FROM users WHERE userId='$userID'");
        while($row = mysqli_fetch_assoc($username)) {
            return $row['userName'];    
        }
    }
}

When calling the function get_username nothing is returned. To verify, I print the session to check the data exists, which it does.

I have also tried just echoing a simple word in the function like this:

function get_username(){
    echo 'test';
}

Again nothing is outputted. As mentioned above the functions.php is included in the head of the page.

Any ideas?

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
danyo
  • 5,686
  • 20
  • 59
  • 119

0 Answers0