使用函数从PHP MySQL数据库驱动的网站获取电子邮件地址的名称

I have a database driven website that has a login to a member or admin area. The login says, "Welcome, Member, pat@email.com" (for example) and I want it to say - "Welcome, Member, Pat" (for example). I have a function that I know works for this, but for some reason I can't get it to work now. It is giving me this error and saying that results is NULL:

Notice: Undefined variable: results in J:\XAMPP\htdocs\tire\admin\home.php on line 59

Below is the two different get_name functions I've tried - note that I have tried one of these and didn't have any trouble getting it to work before.

 function get_name($results) {
    $name = preg_split("/@/", $results['email']);
    $name = ucfirst($name[0]);
    return $name;
 }

function get_name($results) {
list($name, $email) = array_pad(explode('@', $results['name'], 2), 2, null);
  return $name;
 }

And here is the logout form:

<form action="index.php" method="post" id="logoutform.php">

                    <fieldset>
                        <legend>Logout</legend>

                        <?php
                    echo "Welcome, ";
                            echo $_SESSION['level']. ", ";
                            echo $_SESSION['loginName'];

                            echo get_name($results); 
                            var_dump($results);
                    ?>  <br /> <br/> <br/> <br/>
                        <input type="submit" name="action" value="logout"/>

                </fieldset>
                </form>

Connect function:

function connect($loginName) {
    global $db;
    $query = "SELECT email, level, password FROM members WHERE email    = '$loginName'";
    $result = $db->query($query);
    $results = $result->fetch(PDO::FETCH_ASSOC);
    return $results;
 }