PHP mysql将表行与json数组进行比较

I have a mysql table with a firstname, lastname and email which I want to compare with a google spreadsheet array (json) with the same table headers (firstname, lastname, email). If the records match to eachother I want to update my table. For example: I have 'John Doe' in mysql table and 'John Doe' in my google spreadsheet: If this is true I want to update a certain value to this mysql table row.

My code so far, all rows are getting an update because there is one comparison true. I only want the specific rows (Maybe with a foreach?):

$sql = "SELECT * FROM student WHERE form=''"; //select from db
$result = $conn->query($sql);

while($row = mysqli_fetch_array($result)) //fetch it
{       
    $firstname= $row['firstname'];
    $lastname= $row['lastname'];
    $email = $row['email'];

    $url = 'https://spreadsheets.google.com/feeds/list/*MY-KEY*/od6/public/values?alt=json'; // my spreadsheet (key is inserted with me)
    $file= file_get_contents($url);
    $json = json_decode($file);
    $ress = $json->{'feed'}->{'entry'};

    foreach($ress as $res) {

    $fname = $res->{'gsx$naam'}->{'$t'};
    $lname = $res->{'gsx$achternaam'}->{'$t'};
    $mailing = $res->{'gsx$email'}->{'$t'};  
    }       

        if ($firstname.$lastname == $fname.$lname || $email == $mailing) {
            $sql2 = "UPDATE student SET form=1";

            if ($conn->query($sql2) === TRUE) { 
             echo "inserted";
            } 
        }

}

I think you need to change the for loop and the if statement like this

foreach($ress as $res) {

    $fname = $res->{'gsx$naam'}->{'$t'};
    $lname = $res->{'gsx$achternaam'}->{'$t'};
    $mailing = $res->{'gsx$email'}->{'$t'};
    if ($firstname.$lastname == $fname.$lname || $email == $mailing) {
        $sql2 = "UPDATE student SET form=1";

        if ($conn->query($sql2) === TRUE) { 
         echo "inserted";
        }
        // to break from for loop when the record has been found
        break;
    }
}