I need a light, therefore, I am trying to understand this reasoning of the Array in PHP. Here's my headache:
<div class="content">
<form action="" method="POST">
<table>
<thead>
<tr>
<th>ID</th>
<th>Nome</th>
<th>Sobrenome</th>
<th>OBS</th>
</tr>
</thead>
<tbody>
<?php
$sql = mysqli_query($conexaoDados, "SELECT * FROM usuariosBD ORDER BY id DESC");
if(mysqli_num_rows($sql)) {
while($row = mysqli_fetch_array($sql)) {
?>
<tr>
<td><input type="text" name="key[]" value="<?php echo $row['id']; ?>" /></td>
<td><input type="text" name="nome[]" value="<?php echo $row['nome']; ?>" /></td>
<td><input type="text" name="subnome[]" value="<?php echo $row['sobrenome']; ?>" /></td>
<td><input type="text" name="obs[]" value="<?php echo $row['obs']; ?>" /></td>
</tr>
<?php
}}
?>
</tbody>
</table>
<button type="submit" name="submiting">Salvar dados</button>
</form>
In the example above, I will have this data:
<tr>
<td><input type="text" name="key[]" value="123" /></td>
<td><input type="text" name="nome[]" value="Luiz" /></td>
<td><input type="text" name="subnome[]" value="Aurelio" /></td>
<td><input type="text" name="obs[]" value="Usuário premium a partir de Setembro." /></td>
</tr>
<tr>
<td><input type="text" name="key[]" value="124" /></td>
<td><input type="text" name="nome[]" value="Amós" /></td>
<td><input type="text" name="subnome[]" value="Bernadinho da Silva" /></td>
<td><input type="text" name="obs[]" value="Usuário comum a partir de Janeiro." /></td>
</tr>
When I set up PHP, I did this:
<?php
if(isset($_POST['submiting'])) {
$inputs = array(
'ID' => $_POST['key'],
'NOME' => $_POST['nome'],
'SUB' => $_POST['subnome'],
'OBS' => $_POST['obs']
);
foreach($inputs as $row) {
echo $row['ID'];
echo $row['NOME'];
echo $row['SUB'];
echo $row['OBS'];
}
}
? >
Unfortunately, it does not return anything, since they exist. Could someone explain to me where I'm going wrong?