id; $querySelect = "select * from template_criterion where template_id ={$row['id']} and criterion_id = {$criterion_id}"; $makeQuery = mysqli_query($conn, $querySelect); if (!mysqli_num_rows($makeQuery)) { $query2 = "insert into `template_criterion` (`template_id`, `criterion_id`) values ({$row['id']}, {$criterion_id});"; $makeQuery = mysqli_query($conn, $query2); if (!$makeQuery) { echo "Connection failed: " . mysqli_error($conn) . $query2; } } } }