Something is wrong, because before I started to change this line, the same construction worked correctly, and now I always have true for any value of $input , why is that?

 if ($wrd = mysqli_query($link, "SELECT dict_id FROM dict_word WHERE dict_word='".$input."'")) { 
  • it could not work. mysqli_query returns false only if there is an error in the request. In a normal situation, it returns a mysqli_result object from which you can read what the query returned - Mike
  • @Mike, hmm .. probably not seen. I knew about the object, but how could I check if the result was returned or nothing? empty() ? - Telion
  • four
    Apparently check $ wrd-> num_rows. Or use any of the functions fetch_ * php.net/manual/en/class.mysqli-result.php - Mike
  • It seems to me that in general the code is formulated incorrectly, it has never done so in truth. and probably I won't :) - wwwplaton

1 answer 1

You can do something like this:

 $query = mysqli_query($link, "SELECT dict_id FROM dict_word WHERE dict_word='".$input."'"); $count_rows = ($query===false) ? false : mysqli_num_rows($query); if ($count_rows) { ... } 
  • I did a type check !empty($wrd->num_rows) and everything works. Thanks for the answer. - Telion