How to check if at least 1 checkbox has been selected?

2
            $carrosbr = $_POST['carrosbr'];
            $carrosin = $_POST['carrosin'];
            $corp = $_POST['corp'];
            $houses = $_POST['houses'];
            $vip = $_POST['vip'];
            $skins = $_POST['skins'];
            $guns = $_POST['guns'];
            $bases = $_POST['bases'];
            $eventos = $_POST['eventos'];
            $drift = $_POST['drift'];
            $rpg = $_POST['rpg'];
            $mtmt = $_POST['mtmt'];
            $dayz = $_POST['dayz'];

I have the above variables, all are from checkboxes. And I need to check if at least 1 of them is selected.

Help!

    
asked by anonymous 07.07.2016 / 21:31

2 answers

2

With this you check each one. And you can do what you want next.

if(isset($_POST['carrosbr'])) //faça algo
if(isset($_POST['carrosin'])) //faça algo
if(isset($_POST['corp'])) //faça algo
if(isset($_POST['houses'])) //faça algo
if(isset($_POST['vip'])) //faça algo
if(isset($_POST['skins'])) //faça algo
if(isset($_POST['guns'])) //faça algo
if(isset($_POST['bases'])) //faça algo
if(isset($_POST['eventos'])) //faça algo
if(isset($_POST['drift'])) //faça algo
if(isset($_POST['rpg'])) //faça algo
if(isset($_POST['mtmt'])) //faça algo
if(isset($_POST['dayz'])) //faça algo
    
07.07.2016 / 21:49
0

Using array, you could even filter:

if(filter_input_array(INPUT_POST)

In one line, you would treat all $ _POST

    
07.07.2016 / 22:15