I have two tables and I want to count how many 1 is in 1-2 table. If it is same amount than you can insert 1 if not than you can not insert 1 in to the table.
My code insert data even when it is equal or not:
<?php
    $msg = '';
    if(isset($_POST['rogzit_in'])) {
        $barcode = $_POST['barcode'];
        // Belépés ellenőrzése
        if(!isset($_POST['barcode'])) {
            $sql_barcodeInEll = "SELECT COUNT(barcode) FROM log_in WHERE barcode = '$barcode'";
            $result_barcodeInEll = mysqli_query($dbCon, $sql_barcodeInEll);
            $sql_barcodeOutEll = "SELECT COUNT(barcode) FROM log_out WHERE barcode = '$barcode'";
            $result_barcodeOutEll = mysqli_query($dbCon, $sql_barcodeOutEll);
            if(mysqli_num_rows($result_barcodeInEll) != $result_barcodeOutEll) {
                $msg = '<h4 class="col-12 text-center mb-3 text-danger">Már bejelntkezett!</h4>';
            }
        }
        if(isset($_POST['barcode'])) { 
            
                $sql_beszuras = "INSERT INTO log_in(barcode) VALUES ('$barcode')";
                if(mysqli_query($dbCon, $sql_beszuras)) { 
                    ?>
                    <script type="text/javascript">
                    window.location = "home.php/";
                    </script>      
                        <?php     
            }
        }        
    }
?> 
Thank you for the help!
 
    