So I'm not too good in programming but I'm trying to make a login for my site. I've researched a bit and PDO was supposed to be safest for calling mySQL queries.

The problem is I don't get it. I've created a function and got this 2 errors.
First is probably related to another function in functions.php but I'm not sure why.
I've read something about the second one but did not get what I'm supposed to do.

> 
> Errors:
> 
> 
> 1: Warning: Missing argument 1 for userData(), called in page.php on
>  line 34 and defined in functions.php on line 164
> 
> 
> 2:Fatal error: Call to a member function prepare() on a non-object in
>  functions.php on line 165
> 
> 
> 

This is the function I'm trying to run 

```
    function userData(){
        if ($stmt = $mysqli->prepare("SELECT * FROM users WHERE username = ? LIMIT 1")) {
            $stmt->bind_param('s', $_SESSION['username']); 
            $stmt->execute();  
            $stmt->store_result();
            $stmt->bind_result($username);
            $fetch_stmt=$stmt->fetch();

            if ($stmt->num_rows == 1) {
                $username = preg_replace("/[^a-zA-Z0-9_\-]+/", "", $username);
                $_SESSION['username'] = $username;
                $email=$fetch_stmt['email'];
                return array($username,$email);
            } else {
                return false;
            }
        }

    }

```

This function should return an array of user data from database.