Executing mysqli_query works but it does not return exact row given in WHERE CLAUSE

Viewed 41

The query executes .. but let's say for example the user changed the value of $_GET['sub'] to get an id which is not in the database , lets say for example : 60 . it should print "NOT FOUND" instead it prints found ! Why is that ?

 $main = new  MainClass();

 $subid = mysqli_real_escape_string($main->MsqlConRes,$_GET['sub']);

if (is_numeric($subid))
{
    $main->query = mysqli_query($main->MsqlConRes,"SELECT * FROM subjects WHERE id = ".$subid."") or die(mysqli_error());
    if ($main->query)
    {
        echo'Found';
    }
    else
        echo'Not Found !';
}
else
    $main->errors(404);
1 Answers

use mysqli_num_row() in if

if (mysqli_num_row($main->query)>0)
    {
        echo'Found';
    }
    else
        echo'Not Found !';

Since query is executing properly so if ($main->query) will always be true

Related