Rafael Shkembi Rafael Shkembi - 1 year ago 53
SQL Question

if condition does not return true php

i have a variable named

. This variable is going to take 2 values
this depends from the value in the database. Now i'am making the query and i get the value from the db "In our case is ko"

$query="select esito from credit_check where piva is not null and piva='1234656'";
$res_check = $mysqli->query($query);
while($row = mysqli_fetch_assoc($res_check)){
$esito = $row['esito'];

if i echo the
i get "ko"

Now i have this if else condition. if the
is "ko" i will echo "KO" and else i echo "OK".

if($esito == "ko"){
echo "KO";
} else {
echo "OK";

After the if else condition i get "OK". How is this possible?? I sould get "KO" not "OK" i have trying to figure out for the past 30 minutes but i havent found the problem. Thanks all

i have remove the while loop

$row = mysqli_fetch_assoc($res_check);
$esito = $row['esito'];

result is

/var/www/html/credit_check_bo_bt.php:21:string 'ko
' (length=3)

again if i echo the
i get "ko"

if condition is still

Answer Source

Making this a community wiki answer. I have nothing to gain from this.

I'am sorry i have forgot to change the value of piva i get this in var dumb /var/www/html/credit_check_bo_bt.php:21:string 'ko ' (length=3) – Rafael Shkembi 15 mins ago

There you have it, you have a trailing space in your db's value.

Either trim() it, or remove it from your db.

If removing it is impossible because you have too many, then trim() is the way to go.