Save loop for data to database

Asked

Viewed 82 times

0

Good morning I am developing a financial part where I fill out a certain form which is due date, full amount, discounted value, school year, percentage of the discount and amount of portion however before saving those portions in the database I created a loop for to generate the installments according to the amount filled in the form and as a result it brings me only visual installments for the user to check if it’s all right ex:

10/01/2018 = R$ 400.00

10/02/2018 = R$ 400.00

10/03/2018 = R$ 400.00

10/04/2018 = R$ 400.00

now my doubt is the following how do I recover these amounts of installments generated and save in the database why if I put a boot out of the is I can not take for example 4 installments and save in the comic 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;

}                                                              
}
?>
  • post your php code that outlines installments and html so we can help you better

  • ready I think you can understand...lkkkk bad to organize the code Aki

  • that last echo I put so just as an example more in fact in the system here this stylized with all the information the doubt really is how I take this data of the for and saved of the bd

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.