将数据库中的多个值与PHP中的一个文本框值进行比较

I am trying to compare database values with the text box values. For suppose,if the database returns one value then i am able to compare and process the next step. But i am unable to process when multiple values are retrieved from the database. I am using the below code:

Example:

$var = robert;
$query = mysqli_query($con,"select name from hm where class = 8"); 

Database values:

name

steve

Maxy

Rock

if($var != $qwery)
{
//do something;
}
else
{
//do this;
}

Please help me with the problem.Thank You.

You should either loop through the array that is returned, or use something like array_search(), to determine if your desired value is contained within the array.

So I am assuming you are posting the textbox values in a form. You could then do something like this

First I would make an array from your query results.

$arrayToCheck = array();
$query = mysqli_query($con,"select name from hm where class = 8");
while($res = mysqli_fetch_assoc($query)) {
    $arrayToCheck[] = $res['name'];
}

then

if(in_array($_POST['name_from_form'], $arrayToCheck)){
    //do something;
} else {
    //do this;
}