In one of the files I have a PivotTable which receives the data from BD
, but with the possibility of inserting more rows in the table. Note that when I enter more rows the idFaturacao
will be empty.
This is my table:
<TABLE id="dataTable">
<?php
$query_periodosFaturacao = mysqli_query($link,"SELECT * FROM faturacao WHERE fk_obras=$id ORDER BY num_fatura ASC");
while($periodosFaturacao = mysqli_fetch_array($query_periodosFaturacao)) {
echo "<TR>";
echo "<TD width='100px;'><INPUT type='date' id='data_afaturar' name='data_afaturar[]' value='".$periodosFaturacao['data']."' required/></TD>";
echo "<TD><input type='text' name='valor_afaturar[]' id='valor_afaturar' value='".$periodosFaturacao['valor']."' required>€</TD>";
echo "<input type='hidden' name='idFaturacao[]' value='".$periodosFaturacao['id']."' />";
echo "</TR>";
}
?>
</TABLE>
In another file where I send the data to the database, the problem is here! When traversing array
, elements that are empty make INSERT
and elements where idFaturacao
is filled it does UPDATE
of info. I do not know how to check the empty and filled elements in the array.
$data_afaturar = $_POST['data_afaturar'];
$valor_afaturar = $_POST['valor_afaturar'];
$idFaturacao = $_POST['idFaturacao'];
foreach($data_afaturar as $a => $b){
if(empty($idFaturacao[$a])){
echo "INSERT";
}
else{
echo "UPDATE";
}
}
Thank you for your attention!