I am inserting in the same column all the data of my form, which contains checkboxes and inputs type="number":
$calendar .= "<td bgcolor='#F5F5F5' align='center' data-semana=''><center><font size='2px'/>
<input type='checkbox' name='arrachar[$year, $month, $day][dia]' value='$year-$month-$day' $marcado_data $disabled> $year-$month-$day <br />
<input type='checkbox' name='arrachar[$year, $month, $day][OpcaoA]' value='Peq_Almoço' $marcado_pequeno $disabled> Peq. Almoço <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd]' style='width:65px; height: 22px' /> <br />
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoB]' value='Almoço' $marcado_almoco $disabled> Almoço <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd1]' style='width:65px; height: 22px' /> <br />
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoC]' value='Almoço_(Dieta)' $marcado_dieta $disabled> Almoço (Dieta) <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd2]' style='width:65px; height: 22px' /> <br />
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoD]' value='Lanche' $marcado_lanche $disabled> Lanche <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd3]' style='width:65px; height: 22px' /><br />
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoE]' value='Jantar' $marcado_jantar $disabled> Jantar <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd4]' style='width:65px; height: 22px' /> <br />
<input type='checkbox' name='arrachar[$year, $month, $day][opcaoF]' value='Jantar_(Dieta)' $marcado_jantardie $disabled> Jantar (Dieta) <input $disabled type='number' name='arrachar[$year, $month, $day][Qtd5]' style='width:65px; height: 22px' /> </font></center></td>";
}
I'm inserting into the table this way:
if(!empty($_POST['arrachar'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['arrachar'] as $selected){
$string = implode(',', $selected);
$sql="INSERT INTO marcacao (arrachar) VALUES('$string')";
$r = mysqli_query($conn,$sql);
}
}
Here's how you're entering the data:
But I should only insert the first line and should stop, because it was the only day I marked meals, but inserts the remaining days until the end of the month even though they are empty. How can I solve the problem?