-3
Does anyone know why the button of the last while record does not perform the form action?
<?php
while($dados_tabela = $consulta_tabela -> fetchObject()) {
?>
<tr>
<td><?php echo $dados_tabela->id; ?></td>
<td><?php echo $dados_tabela->nome; ?></td>
<td><?php echo $dados_tabela->usuario; ?></td>
<td><?php echo $dados_tabela->senha; ?></td>
<td><?php echo $dados_tabela->email; ?></td>
<td align="center">
<table>
<tr>
<td>
<form name="editar_usuario" action="../php/editar_usuario.php" method="post">
<input type="hidden" name="id_editar" value="<?php echo $dados_tabela->id; ?>" />
<button type="submit" class="btn btn-default btn-xs"><i class="fa fa-edit"></i></button>
</form>
</td>
<td>
<form name="excluir_usuario" action="../php/excluir_usuario.php" method="post">
<input type="hidden" name="id_excluir" value="<?php echo $dados_tabela->id; ?>" />
<button type="submit" class="btn btn-default btn-xs"><i class="fa fa-trash-o"></i></button>
</form>
</td>
</tr>
</table>
</td>
</tr>
<?php
}
?>
You cannot place the same form within a loop, put the form name and the form id, as a key variable, concatenating with the names.
– Ivan Ferrer
Ivan actually "can", but is completely NOT recommended by myriad haha problems
– Ademílson F. Tonato
It may just that it will always overwrite the information.
– Ivan Ferrer
@Ivanferrer , could pass me how this amendment would look?
– Ezequiel Tavares
Why don’t you use
foreach
?– KingRider
I will present a better solution by avoiding this Forms loop... because this really is not a good practice.
– Ivan Ferrer
@Ivanferrer thanks for the solution via javascript however now it did not work at all. i didn’t want to go through $_GET to not be visible in the URL but I will try to call $_GET in the url of an iframe or by include but there is no idea how to implement
– Ezequiel Tavares
i edited, it had a variable more "form". that was actually the name of the form.
– Ivan Ferrer
It has how to put the part of the query code, and the output of a
print_r( $consulta_tabela );
to evaluate? By the way, not related to the question, but you can have a good dry HTML later, reorganizing the table outside. A good test is to see if there is no other element of the page with z-index larger than the desired button, which you can not analyze just by looking at your code.– Bacco
And remove the excluir_user and editar_user from the Forms, it has no use in this case, and generates repeated names.
– Bacco
The problem of doing this: when you submit the post request, the HTML document looks for the <form> header, each form is an array and each element of the form is another array... if you put the same name, it is the same as always taking the same array key, it will search for the attribute of that array and will not find it because it was in another form of the same key. And he doesn’t make that distinction And he doesn’t make that mixture.
– Ivan Ferrer
exactly @Ivanferrer think I’ll put form name concatenated with the recovered line id in the query so it doesn’t get the same form name on all lines.
– Ezequiel Tavares
I did what I said but unsuccessfully too. in case in each row would be a form with different name. unsuccessfully
– Ezequiel Tavares