• I’m very new to PHP programming, so excuse me for asking this (most likely) dumb question.
    I’ve added a new page to my WordPress by creating a template. This template contains code for retrieving the logged-in user’s ID and name. This information needs to be emailed.

    So in the WP template I have this;


    // retreive information about this user
    GLOBAL $fb_currentUserID;
    GLOBAL $fb_currentName;

    $fb_currentUserID = get_current_user_id();
    echo ($fb_currentUserID);

    $fb_currentNameQuery = mysql_query("SELECT user_nicename FROM wp_users WHERE ID = “.$fb_currentUserID.””);
    $fb_currentNameArray = mysql_fetch_array($fb_currentNameQuery);
    $fb_currentName = $fb_currentNameArray[‘user_nicename’];
    echo ($fb_currentName);

    These echo’s ($fb_currentName and $fb_currentUserID) show up just fine. But when I use them in this function (a little further down in the code), nothing is displayed.


    function mailInvitation($email, $pass) {
    $subject = "You're invited by".$fb_currentName."";
    echo ($subject);
    $body = "Hi,\n\nTo register your account, please surf to http://localhost/invite?pass=".$pass."";
    if (mail($email, $subject, $body)) {
    echo("<p>Message successfully sent!</p>");
    } else {
    echo("<p>Message delivery failed...</p>");
    }
    }

    Here the $subject only shows ‘You’re invited by’. It doesn’t want to print the $fb_currentName even though I thought to have it setup as a global variable.

    Can anyone tell me what I’m doing wrong?

The topic ‘Global variable not available in function’ is closed to new replies.