0
I have this table above , and I have the add button to add a row to this table , as in the image below.
I wonder if you have how to save this new data from the line added in the database
follows my code adding line
<script>
$("#adicionar").bind( "click", function() {
var $tbody = $("#calculaTotal > tbody" );
var $tr = $tbody.children( "tr:first" ).clone();
$tr.each( function() {
$( this ).find( "input" ).val( "newimput" );
});
$tbody.append( $tr );
});
</script>
and this is the code of my table
<table id="calculaTotal" class="table table-bordered" style="border:2px solid">
<thead>
<tr>
<th style="border:2px solid">Preço R$</th>
<th style="border:2px solid">Quantidade </td></th>
<th style="border:2px solid">Descrição</th>
<th style="border:2px solid">Codigo</th>
</tr>
</thead>
<tbody >
<tr style="border:2px solid">
<td style="border:2px solid"><input type="number" name="preco"id="preco"/> </td>
<td style="border:2px solid"><input type="number" name="quantidade" id="quantidade"/></td>
<td style="border:2px solid">
<select id="desc" class="selecter" data-live-search="true" name="descr">
<?php
$dados =mysqli_query($connect,"SELECT * FROM produtos");
while($exibe = mysqli_fetch_array($dados)) { ?>
<option name="desc" value="<?php echo $exibe['Descricao'] ?>"><?php echo $exibe['Descricao'] ?></option>
<?php } ?>
</select>
</td>
<td style="border:2px solid">
<select id="cod" name="codi">
<option name="selecione">-</option>
<?php
$dados =mysqli_query($connect,"SELECT * FROM produtos ");
while($exibe = mysqli_fetch_array($dados)) { ?>
<option name="Cod" value="<?php echo $exibe['Codigo'] ?>"><?php echo $exibe['Codigo'] ?></option>
<?php } ?>
</select>
</td>
</tr>
</tbody>
<label for="">Selecione um Cliente</label><br/>
<select id="cliente" class="form-control" >
<?php
$dados2 =mysqli_query($connect,"SELECT * FROM clientes");
while($cliente=mysqli_fetch_array($dados2)){ ?>
<option data-codigo="" name="Cliente" id="cliente" value="<?php echo $cliente['Cliente'] ?>"><?php echo $cliente['Cliente'] ?></option>
<?php }?>
</select>
</table>
Is the Javascript code working correctly? Can’t you just receive all the values in PHP? If so, just add
[]
toname
of the fields, such asname="preco[]
,name="quantidade[]
, etc. Thus, the value of$_POST['preco']
will be a list of all prices filled.– Woss
@Andersoncarloswoss yes javascript ta working correctly ,I will test after that Voce spoke, thanks
– Lucas Ln