I am trying to find and echo one result from my database. I am using it like below
<?php
error_reporting(E_ALL);
include_once("includes/connection.php");
$input = "OUT";
$answer = $mysqli->query("SELECT answer FROM faq WHERE question LIKE '%".$input."%' LIMIT 1")->fetch_object()->answer;
echo $answer;
?>
Its working fine when there some result but giving error like below when there no any result
Notice: Trying to get property 'answer' of non-object in C:\xampp\htdocs\new\test.php on line 5
I want handle this error using if else. I do not know much PHP and specially does not know more about query. Let me know if someone can help me for get out from this. Thanks