I am working on php and javascript project. I just want to compare echo return value of php with javascript variable.
php backend code which returns 'no' using echo
if($connection){
$sql ="SELECT secondname FROM account WHERE email = '$email' && password = '$password'";
$searchquery = mysqli_query($connection, $sql);
if(!(mysqli_num_rows($searchquery) == 0)) {
$row = mysqli_fetch_array($searchquery);
$secondname = $row['secondname'];
echo $secondname ;
} else {
echo 'no';
}
Now comparing with javascript variable
$.post("signnin.php",{
email: email,
password: password,
},
function(data, status){
if(data == 'no'){
console.log('same');
}else{
console.log('not same');
}
});
it give same result if value are same or not. i also JSON.stringify but it still not working
dataactually contains..? I would assume that the problem is because you're returning a plain text response and there's some whitespace you need to remove withtrim(), egif (data.trim() === 'no'). This is why it's always a better idea to return a serialised response.AND, not&&.&&is non-standard SQL and is deprecated in MySQL 8 and will be removed in a future version.