Save data from the for loop in the database

0

Good morning I'm developing a financial part where I fill in a certain form that is due date, full value, discount value, school year, discount percentage and installment amount before saving those installments in the database I created a for loop to generate the plots according to the amount filled in the form and as a result it brings me the only visual plots for the user to check if this is all right ex:

10/01/2018 = $ 400.00

10/02/2018 = $ 400.00

10/03/2018 = $ 400.00

10/04/2018 = $ 400.00

Now my doubt is the following as I do to recover those quantities of generated parcels and save in the database because if I put a button out of the I can not get for example 4 parcels and save in the bd and only one .

<form role="form" method="post" class="">
<div class="form-body">


<div class="form-group">

<label>ano letivo</label>
<input class="form-control spinner" type="text" name="ano_letivo" value="<? 
php echo date('Y'); ?>" />

</div>

<div class="form-group">
<label for="nMatricula">Numero de Matricula</label>

<input type="text" name="matricula" class="form-control" id="nMatricula" 
placeholder="Matricula"> 
</div>


<div class="form-group">
<label for="nomealuno">Nome do Aluno</label>
<input type="text" disabled="" name="nome_aluno" class="form-control" 
id="nomealuno" placeholder="nome do aluno"> 
</div>

<div class="form-group">
<label>valor da mensalidade</label>

<input class="form-control spinner" type="text" name="valor1" id="valor1" 
value="583.02" />
</div>

   discount%

<input class="form-control spinner" type="text" name="desconto1" 
id="desconto1" onblur="calcValor()" />
</div>                 

<div class="form-group">
<label>valor total</label>

<input class="form-control spinner" type="text" name="total" id="total" 
value="0.00" />
</div>

<div class="form-group">
<label>nº de parcelas</label>

<input class="form-control spinner" type="text" name="n_parcelas" value="12" 
/>
</div>      

<div class="form-group">
<label>dia de vencimento</label>

<input class="form-control spinner" type="text" name="dt_vencimento" 
id="dt_vencimento" />
</div>                                                       
</div>
<div class="form-actions">
<button type="submit" name="gerar" class="btn green-meadow">Visualizar 
Parcelas</button>
<a href="home.php" class="btn red">Cancelar</a>
</div>
</form>

<?php 

if (isset($_POST['gerar'])) {

$vl_mensalidade = $_POST['valor1'];
$matricula = $_POST['matricula'];
$ano_letivo = $_POST['ano_letivo'];
$desconto = $_POST['desconto1'];
$vl_desconto = $_POST['total'];
$n_parcelas = $_POST['n_parcelas'];
$dataPrimeiraParcela = $_POST['dt_vencimento'];

if($dataPrimeiraParcela != null){
$dataPrimeiraParcela = explode( "/",$dataPrimeiraParcela);
$dia = $dataPrimeiraParcela[0];
$mes = $dataPrimeiraParcela[1];
$ano = $dataPrimeiraParcela[2];
} else {
$dia = date("d");
$mes = date("m");
$ano = date("Y");
} 

for ($x=0; $x < $n_parcelas; $x++) {

$vencimento = date("d/m/Y",strtotime("+".$x." month",mktime(0, 0, 
0,$mes,$dia,$ano)));

echo "Vencimento: ".$vencimento." - ".$vl_desconto;

}                                                              
}
?>
    
asked by anonymous 14.09.2018 / 16:50

0 answers