Something is wrong with my php,

I'm doing an account validation where if the data exist it will display "There is data" and else "No data"...

When I enter the first 'row' reference\_id and submit, it shows "There is data" which is correct but when I entered the second to the last 'row' reference\_id it shows "No data" even though it exist in my Database! 

Database:

```
reference_id (varchar 250)
status (varchar250)

```

PHP 

```
if (isset($_POST['submit_valid'])) {

    if (!empty($_POST['reference_id'])) 
    {

        $query = mysqli_query($con, "SELECT * FROM client_record");
        $result = mysqli_fetch_array($query);

            if ($result['reference_id'] == $_POST['reference_id'])
            {
               echo"<script type='text/javascript'> alert('There is data'); window.location.href='next_page.php';  </script>";         
            }

            if ($result['reference_id'] !== $_POST['reference_id']) {
                echo"<script type='text/javascript'> alert('No data.'); window.location.href='this_page.php';  </script>";
            }
    } 
}

```

I am not sure if it's the `mysqli_fetch_array` fault or the if-else condition is wrong?

if you guys know the problem please help me?