两个单独的表,如何检查用户是否是更新其他表的所有者

I have to tables One with users Other with images

They both have one column in common which is the 'type', for example "landscape"

How do I update a row in images only if the person who login has the same 'type' as the image

$sql = "UPDATE images SET display=? WHERE id =?";
$query = $this->db->prepare($sql);
$query->execute(array($action, $id));

That works now I just need to add security so not any user can update any row. In my session I have 'type', do i just make another query that gets the 'type' from images then compare and keep them seperate?

You can check this based on the user data of the logged-in user.

$sql = "UPDATE images SET display=? WHERE id =? AND type=?";
$query = $this->db->prepare($sql);
$query->execute(array($action, $id, $user_data->type));

It's a bit more secure but users from the same type can still update all the images, maybe that's correct behavior. If not, define via another query which user can access/update a image.