I have a table with records
id(int) nombre(varchar(50))
1 juan
2 pedro
4 aldo
When executing my sentence
$size = count($_POST['id']);
$i = 0;
while ($i < $size) {
$id1= $_POST['id'][$i];
$nombre1 = $_POST['nombre'][$i];
$query = "INSERT INTO datosp (id,nombre)
VALUES ('$id1','$nombre1')";
sqlsrv_query($conn, $query) or die (print_r( sqlsrv_errors(), true));
++$i;
}
You are only inserting datap in the table
id nombre
1 juan
2 pedro
This is my form:
<?php
$sql = "SELECT * FROM usuario ORDER BY id ASC";
$result = sqlsrv_query($conn, $sql);
$i = 0; ?>
<form name='form_update' method='post' action='update.php'>
<?php while ($usuario = sqlsrv_fetch_array($result)) {
$id=$usuario['id'];
$nombre=$usuario['nombre'];
echo '<tr>';
echo "<td>{$usuario['id']}<input type='hidden' name='id[$i]' value='{$usuario['id']}' /></td>";
echo "<td>{$usuario['nombre']}<input type='hidden' name='nombre[$i]' value='{$usuario['nombre']}' /></td>";
echo '</tr>';
++$i;
} ?>
<tr>
<td><input type='submit' value='Generar Periodo Actual' class='btn btn-info' data-toggle='confirmation' /></td>
</tr>
</form>
It does not mark me wrong or anything and I already have a time stuck with this.
Thank you in advance.