0
I am entering 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 it 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 I show you how you are entering the data:
But I was only supposed to insert the first line and I was supposed to stop because it was the only day I booked meals, but it inserts the remaining days until the end of the month even though they were empty. How can I solve the problem?
When you say you use the same
insert
, you include the column for thevalues
of the correct "number" inputs?– Ricardo Pontual
No, I’m trying to enter all the data in the same column, in the array column where I enter the checkboxes
– Bruno
I changed the name of the inputs type="number" and I use exactly the same name as the one I posted above, but insert many empty lines as shown in the question.
– Bruno
if Voce is concatenating all the $Selected variables inside the $string, you need to do the Insert only after q it exits the is...
– Michel Simões
I see the code
if(!empty($_POST['arrachar'])){
should be inside theforeach
and not before it, then you will check whether each control is empty or not. As it stands, only the first is checked.– Andrey
But still inserts the other lines, inserts this way:
1 2018-04-21,Peq_Almoço,10,Almoço,10,,Lanche,10,,
2 ,,,,,
3 ,,,,,
4 ,,,,,
5 ,,,,,
6 ,,,,,
7 ,,,,,
8 ,,,,,
9 ,,,,,
10 ,,,,,
, should only insert the first line– Bruno