user887799
user887799

Reputation:

Why "if( variable = class)" return false?

I have this piece of code:

$username = strip_tags($_POST['username']);
$password = strip_tags(md5($_POST['password']));
require_once '../classes/Login.php';
$Login = new Login;
if($message = $Login->checkUserLogin($username,$password))
 echo $message;
}
else{
 echo "Houston, we have problem";
}

And it write: "Houston, we have problem"

So I'm wondering why?

Sorry for my english. I hope you understand me!

Upvotes: 0

Views: 118

Answers (2)

Nonym
Nonym

Reputation: 6299

I don't think you can assign a variable in an IF statement unless you'll simultaneously compare it to another variable or value. Here's another suggestion:

$username = strip_tags($_POST['username']);
$password = strip_tags(md5($_POST['password']));
require_once '../classes/Login.php';
$Login = new Login;
$message = $Login->checkUserLogin($username,$password);
if($message != '') {
 echo $message;
}
else{
 echo "Houston, we have problem";
}

Sorry, there I go again with a suggestion. If you really just want to know why it doesn't work, I don't know how else to answer your question.

However, if you had something to compare $message to, you can use this!:

    if($messageToCompare == $message = $Login->checkUserLogin($username,$password)) {

It should help.

Upvotes: 1

Peter
Peter

Reputation: 16943

This is just simple debbugging problem, not question for Stack Overflow...

var_dump( $Login->checkUserLogin($username,$password) );

will return int(0) or bool(false) or NULL

Upvotes: 0

Related Questions