1
I need a light, because, I’m days trying to understand this reasoning of Array in PHP. Follow 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 building PHP, I did it this way:
<?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 am missing?
thanks. You made it clear and also solved the doubt. : D Hugs.
– user93488
@Robson quiet... Even I was getting confused! I almost went looking for a php course for me. rsrs.. Hug!
– Andrei Coelho