I'm trying to make a reputation system:
if($upvotetruedownvotefalse == false){
if(strpos($lines[2],$username.",") !== false){
echo "you've already downvoted";
}
else{
echo "you haven't downvoted yet";
$lines[2] = $username.",".$lines[2];
$lines[0] = $lines[0]-1 . "\n";
file_put_contents( $filename , $lines);
}
}
if($upvotetruedownvotefalse == true){
if(strpos($lines[1],$username.",") !== false){
echo "you've already upvoted";
}else{
echo "you haven't upvoted yet";
$lines[1] = $username.",".$lines[1];
$lines[0] = $lines[0]+1 . "\n";
file_put_contents( $filename , $lines);
}
}
The value of $upvotetruedownvotefalse
is determined through AJAX
However these comparison operators is giving me wrong results.
For example if $upvotetruedownvotefalse = false
then $upvotetruedownvotefalse == true
would be triggered. I've tested this by echoing the value of $upvotetruedownvotefalse
and recieving the echo results (including the ones in the if statements)using a success function:
echo $upvotetruedownvotefalse;
success: function(response){
alert(response);
}
Then I console.log the result and i would get this:
Falseyou haven't upvoted yet
I'm getting conflicting results. I've also tried using different types of === !===
in different places and I get either an inverted result or my success function fails
Is there something that I don't know about Boolean operators? Any help would be greatly apreciated
Aucun commentaire:
Enregistrer un commentaire