I’ve just created a facebook app, all was smooth till spot on this strange problem with my code.
At one place in my code it retrieves user gender from Facebook graph api correctly and then compare it for some working but suddenly after the if else comparison the values of parameters changes automatically.
$userGender = json_decode(file_get_contents('http://graph.facebook.com/'.$userId)) -> gender;
$gender = "";
echo "userGender: " . $userGender . "<br/>";
if ($userGender = "male") {
$gender = "Man";
} else if ($userGender = "female") {
$gender = "Woman";
}
echo "userGender: " . $userGender . "<br/>";
echo "gender: " . $gender . "<br/>";
The above code is giving following output (to keep in mind the real gender of this user is ‘female’):
userGender: female //Correct output
userGender: male // Wrong output
gender: Man //Wrong output
I am totally lost with this problem,. Kindly help me go through it and its creating serious problems for me in the run.
Thank you
You are using the assignment operator and not ==.
Correct Code: