I have a table with a form to show me the registered users on one side and the input of each one to fill in on the other, but when filling in the data it gives me an error. Here is the form. This is the solution that was given to me. I will be waiting to respond as quickly as possible
<form method="POST">
<table class="table table-striped table-sm table-bordered table-hover">
<div class="col-3">
<label for="fechaAporte"><h3><b>Fecha del Aporte</b></h3></label>
<input type="date" class="form-control" name="fechaAporte" required>
</div>
<br>
<thead class="thead-dark">
<tr>
<th>Cedula</th>
<th>Nombre</th>
<th>apellido</th>
<th>Aporte Asociado</th>
<th>Fecha Pago del Asociado</th>
<th>Aporte Patronal</th>
<th>Fecha del Aporte Patronal</th>
<th>Total del Monto Aportado</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
<?php
$resultadoBus = mysqli_query($mysqli, "SELECT * FROM asociado WHERE tipoUsuario = 2");
while ($row = mysqli_fetch_array($resultadoBus)) {
?>
<tr>
<td><?php echo $row['cedula']; ?></td>
<td><?php echo $row['nombre']; ?></td>
<td><?php echo $row['apellido']; ?></td>
<!-- while de Haberes -->
<td><input type="number" name="aporteAsociado[]" class="form-control" id="aporte1" ></td>
<td><input type="date" name="fechaPagoAsociado[]" class="form-control" id="fechaPagoAsociado" ></td>
<td><input type="number" name="aportePatrono[]" class="form-control" id="aporte2"></td>
<td><input type="date" name="fechaAportePatrono[]" class="form-control" id="fechaAportePatrono"></td>
<td><input type="number" name="montoAporte[]" class="form-control" id="total"></td>
<input type="hidden" name="cedulaArray" value="<?php echo $row['cedula']; ?>">
<td>
<button type="submit" name="btnCrearHaber" class="btn btn-success">Registrar Aporte</button>
</td>
<tr>
<?php } ?>
</tbody>
</table>
</form>
And here is the PHP to save the data, I imagine that it is the one that is giving me errors in the logical part, I tried to hit it with these arrays using a variable to go through but it does not save anything in the database
if (!empty($_POST)){
if(isset($_POST['btnCrearHaber'])) {
$contadorHaber = count($_POST['cedulaArray']);
for($i = 0; $i<$contadorHaber; $i++){
$cedulaAsociado = $_POST['cedulaArray'] [$i];
$fechaAporte = $_POST['fechaAporte'] [$i];
$aporteAsociado = $_POST['aporteAsociado'] [$i];
$fechaPagoAsociado = $_POST['fechaPagoAsociado'] [$i];
$aportePatrono = $_POST['aportePatrono'] [$i];
$fechaAportePatrono = $_POST['fechaAportePatrono'] [$i];
$montoAporte = $_POST['montoAporte'] [$i];
$estado = 0;
$insertando = "INSERT INTO haber (cedulaAsociado, fechaAporte , aporteAsociado, fechaPagoAsociado, aportePatrono, fechaAportePatrono, montoAporte, estado)
VALUES ('$cedulaAsociado', '$fechaAporte', '$aporteAsociado', '$fechaPagoAsociado', '$aportePatrono', '$fechaAportePatrono', '$montoAporte', '$estado')";
$resultado = mysqli_query($mysqli, $insertando);
}
REMOVE THE KEYS IS NOT NECESSARY
I tell you that what seems to be your error starts from the form, I recommend that you do not try to send all the information in one fell swoop, that will only make your code more complicated
At a graphic level this will not change how you see the data, but at a logical level it will make everything much simpler, from here the only thing you have to do is pass all your data to the backend and interpret it, it should be something like
This way you have more control over everything that enters your system.