1

No doubt there is a very quick and easy solution for this but I can’t seem to get my head around it. How would I go about returning the variable $errMsg from the function below? So I can display it on the page where the function is being called.

function login(){

    global $wpdb;

    if( isset($_POST['login_btn'] )){


        if (empty($_POST['login_username'] || empty($_POST['login_password']))) {

            $errMsg = 'Invalid Username or Password';
            return $errMsg; 

        }else {

            $login_username = $_POST['login_username'];
            $login_password = $_POST['login_password'];

            $u = $login_username;
            $p = $login_password;


            $query = $wpdb -> prepare("SELECT * FROM 'wp_members' WHERE     'username' = %u AND 'password' = %p", $u, $p );

            // If there is a matching username and password then redirected to login
            if ($query == true) {

                $_SESSION['login_username'] = $login_username;          
                header('Location: /flourishWP/wp-content/themes/blankslate/includes/admin.php');    
            }
        }
    }
}
1
  • Did you try echo $errMsg ? Commented Oct 8, 2015 at 9:48

3 Answers 3

3

$someVar = login(); now inside $someVar you have returned values of your function

Sign up to request clarification or add additional context in comments.

Comments

1

Try using echo

    if (empty($_POST['login_username'] || empty($_POST['login_password']))) {

        $errMsg = 'Invalid Username or Password';
        echo $errMsg; 

    }

Comments

0

Very simple:

$errmsg = login();

if($errmsg != null){
    echo $errmsg;
}

You call the function and if there is an error message you display it.

1 Comment

But call it outside the login() function ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.