A
In principle your logic in if He's saying the condition has to be If bothA and B (AND) is true then... Until that condition is fulfilled, for example:else if ($_POST['01'] == '01' and $_POST['02'] == '02' ){
$consulta = "
INSERT INTO gastonocomun
VALUES(
'','$monto','$tipo',
'2018-01-01','2018-02-01',
'','','','','','','','','','','$gasto')";
$query = mysqli_query($conexion, $consulta);
}
It's just that Yes and only if Enero and Febrero they are marked must be fulfilled. But if it turns out you can skip a month like, for example:else if (
$_POST['01'] == '01' and
$_POST['02'] == '02' and
$_POST['03'] == '03' and
$_POST['04'] == '04' ){
If I don't fit here Marzo But yes. Abril, this code would not run, nor any other. So on the one hand, in practice you should keep in an array the checked checkboxes, and this you do, telling him in "Name" That's an arrangement. <input type="checkbox" name="mes[]" value="01" > Enero<br>
<input type="checkbox" name="mes[]" value="02"> Febrero<br>
<input type="checkbox" name="mes[]" value="03"> Marzo<br>
<input type="checkbox" name="mes[]" value="04"> Abril<br>
<input type="checkbox" name="mes[]" value="05"> Mayo<br>
<input type="checkbox" name="mes[]" value="06"> Junio<br>
<input type="checkbox" name="mes[]" value="07"> Julio<br>
<input type="checkbox" name="mes[]" value="08"> Agosto<br>
<input type="checkbox" name="mes[]" value="09"> Septiembre<br>
<input type="checkbox" name="mes[]" value="10"> Octubre<br>
<input type="checkbox" name="mes[]" value="11"> Noviembre<br>
<input type="checkbox" name="mes[]" value="12"> Diciembre<br>
Then we go through the arrangement with a Foreach() and we get the values from every Checkbox.foreach ($array as $value) {
}
and depending on its value, you insert into the DB according to the handles. You can separate the months in Variables separated by months, and you pass the variables to the, question that if it does not exist, it will be empty.EDIT/2005 $QueryYour Query should have something like this:$consulta = "
INSERT INTO gastonocomun
VALUES('','$monto','$tipo','$ene','$feb','$mar','$abr','$may','$jun','$jul',
'$ago','$sep','$oct','$nov','$dic','$gasto')
";
$query = mysqli_query($conexion, $consulta);
The idea of foreach is to go through the Checkbox to determine the ones selected and give the values to their respective variables ($ene, $feb, etc).The conditional if, you should use it only to validate that a Checkbox has been selected, and so send the Query.