0
In this script below I make a loop in rows of a table, where it contains in each row a checkbox and hidden inputs.
The problem is that when I select a few lines with the checkbox, the values corresponding to the checkbox come correct plus the other inputs come as taking data from the unmarked lines
php test.
<form id="form2" name="form2" action="acao.php form=cotacao" method="POST">
<table>
<tr>
<td><input name="checkbox[]" type="checkbox" value="<?echo $id_produtos>"/>
</td>
<td><?echo $id_produtos?></td>
<td><input type="hidden" name="nome[]" value="<?echo $nome?>" /></td>
<td><input type="hidden" name="tipo_serv[]" value="<?echo $tipo_serv?>" />
</td>
<td><input type="hidden" name="valor[]"value="<?echo $valor?>" />
</td>
</tr><input type="submit" value="Gerar"/>
acao.php
if (isset($_POST['checkbox'])) {
foreach ($_POST['checkbox'] as $key => $value) {
echo $id_saida = mysql_real_escape_string($value);
$tipo = mysql_real_escape_string($_POST['tipo_serv'][$key]);
echo $nome = mysql_real_escape_string($_POST['nome'][$key]);
$start = mysql_real_escape_string($_POST['start'][$key]);
echo $valor = mysql_real_escape_string($_POST['valor'][$key]);
$desconto = mysql_real_escape_string($_POST['desconto'][$key]);
$tipo_veiculo=mysql_real_escape_string($_POST['tipo_veiculo'[$key]);
Hello Friend excuse my ignorance , but I couldn’t adapt in my code, to put here https://3v4l.org/L79GG , https://3v4l.org/L2SoW the real code as I use today
– Fabio Henrique
Your code is too long, for that very reason I isolated and answered the question based on an example I made. But the implementation on yours shouldn’t be difficult, where you have the attributes
name="nome[]"
,name="tipo_serv[]"
,name="id_produto[]"
and others, just put<?echo $id_produtos?>
as an index in attributesname
, as follows:name="tipo_serv[<?echo $id_produtos?>]"
, and so on.– Edilson
Hello Amigo I did as suggested most when it only comes the checkbox id. to do so https://3v4l.org/muCMG
– Fabio Henrique
Look, try this: https://3v4l.org/ErSeU
– Edilson