I'm having a problem passing values of inputs with same name, that was working but now tha just doesnt work anymore here is the html and the php
html:
<form action="alterado.php" method="post">
<p class="codigo"><input type="text" name="codigo-peca[]"></p>
<p class="descricao-peca"><input type="text" name="descricao-peca[]"></p>
<p class="valor-peca">R$<input type="text" name="valor-peca[]"></p>
<p class="codigo"><input type="text" name="codigo-peca[]"></p>
<p class="descricao-peca"><input type="text" name="descricao-peca[]"></p>
<p class="valor-peca">R$<input type="text" name="valor-peca[]"></p>
<input type="submit" value="Salvar Dados">
alterado.php
if(is_array($_POST['valor-peca']) && is_array($_POST['codigo-peca']) && is_array($_POST['descricao-peca']) ) {
// ... code
for($i = 0; $i < count($_POST['valor-peca']); $i++) {
// ... reference index of arrays
$valorPeca = $_POST['valor-peca'][$i];
$codigoPeca = $_POST['codigo-peca'][$i];
$descricaoPeca = $_POST['descricao-peca'][$i];
if ($valorPeca != 0){
$SQL = "INSERT INTO pecas (ordemServico, codigoPeca, descricaoPeca, valorPeca) VALUES ('$ordem', '$codigoPeca', '$descricaoPeca', '$valorPeca');";
$result = mysql_query($SQL);
}
}
}
but that is reading only the first input value but not the second