-2
<form method="POST" action="proc_editar_despacho.php">
<div class="form-group">
<div class="card">
<div class="card-body">
<label for="exampleInputEmail1">ITEM</label>
<input type="text" name="item[]" class="form-control" readonly value="<?php echo $row_despacho_itens['item']; ?>">
<br/>
<label for="exampleInputEmail1">DESCRIÇÃO</label>
<textarea class="form-control" name="descricao[]" rows="3"><?php echo $row_despacho_itens['descricao']; ?></textarea>
<br/>
<label for="exampleInputEmail1">UF</label>
<input type="text" name="uf[]" class="form-control" value="<?php echo $row_despacho_itens['uf']; ?>">
<br/>
<label for="exampleInputEmail1">QTDE</label>
<input type="number" name="qtde[]" class="form-control" value="<?php echo $row_despacho_itens['qtd']; ?>">
<br/>
<label for="exampleInputEmail1">PU EM R$</label>
<input type="text" name="pu[]" class="form-control" value="<?php echo $row_despacho_itens['preco_unitario']; ?>">
<br/>
<label for="exampleInputEmail1">PT EM R$</label>
<input type="text" name="pt[]" class="form-control" value="<?php echo $row_despacho_itens['preco_total']; ?>">
</div>
</div>
<?php }?>
<br/>
</div>
<button type="submit" class="btn btn-primary">Editar</button>
</form>
PHP
for($i = 0; $i < $contador; $i ++){
$result_item = "UPDATE tb_itens SET descricao='$descricao[$i]', uf='$uf[$i]', qtd='$qtde[$i]', preco_unitario ='$pu[$i]', preco_total='$pt[$i]' WHERE id_despacho='$id_despacho' ";
$resultado_item = mysqli_query($conn, $result_item);
}
if(mysqli_affected_rows($conn)){
$_SESSION['msg'] = "<p style='color:green;'>Editado com sucesso</p>";
header("Location: ../consultar.php");
}else{
$_SESSION['msg'] = "<p style='color:red;'>Não foi editado </p>";
header("Location: ../login.php");
}
Gives error only to change the last record
have you tried debugging to find out what causes this error? or tried to grab the command
update
and run straight into the bank?– Ricardo Pontual