Calculate boleto / parcel in PHP [closed]

1

I have an HTML form which, after being filled, field values are sent via POST method to a file in PHP and this file captures these values, sending to the MySQL database.

My problem is in the calculation of installments. If I make a purchase installment in 5 times, for example, in the form I put the account data, the amount of installments and the first maturity. PHP takes the first maturity (date) and adds another 4 plots. That is, if the first installment is 05/06/2017, the next 4 installments would be: 05/07, 05/08, 05/09 and 05/10/2017. The problem is that when you run the form, it returns a blank page and does not write anything to MySQL. The connections are correct, there is a PHP errorback in case of a code error and so on.

Follow the snippet for help:

if($parcelado == "Sim") {

    $opcoes = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8');
    $conexao = new PDO("mysql:host=".SERVER."; dbname=".DBNAME, USER, PASSWORD, $opcoes);

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

        $timestamp = strtotime("+ $nParcela month");
        //$date('d/m/Y H:i', $timestamp);

        $sql  = "INSERT INTO boleto(nome_boleto,data_inclusao,vencimento,valor_boleto,descricao,pago,nParcela, dataparcela) VALUES ('$boleto', '$dtpgto', '$timestamp', '$pagamento', '$descricao', '$pago', '$nParcela')";

        $stm = $conexao->prepare($sql);
        $stm->execute();
    }

}   

In the form has a field (Parcel?) if yes, enter this condition, if not enter another.

Follow the variables:

$dbpgto1 = $_POST['payment'];
$dtvencimento1 = $_POST['maturity'];
$boleto = $_POST['invoice'];
$dtpgto = date("Y-m-d",strtotime(str_replace('/','-',$dbpgto1)));
$dtvencimento = date("Y-m-d",strtotime(str_replace('/','-',$dtvencimento1)));
$pagamento = $_POST['value'];
$mensal = $_POST['radiosmensal'];
$descricao = $_POST['textarea'];
$nParcela = $_POST['nParcela'];  
$dataParcela = $_POST['dataparcela'];    
$pago = "Nao";
#$dataPrimeiraParcela = $_POST['dataparcela'];
#$nParcelas = $POST_['nParcela'];
$parcelado = $_POST['radiosparcelado'];

Finally, if I put a echo at the end of for , it returns what I put in it.

    
asked by anonymous 05.06.2017 / 20:05

1 answer

1

You have come to analyze the return of all variables from what goes into the database

Type you designed 8 columns but only by inserting 7.

$date1 = explode("/", $dbpgto1);
$date2 = explode("/", $dtvencimento1);
$dtpgto = date("Y-m-d",mktime(0, 0, 0, $date1[1], $date1[0], $date1[2]));
$parcela = 7;

for($i=0; $i <= $parcela; $i++){

    $nParcela = $i;

    $dtvencimento = date("Y-m-d",strtotime("+".$i." Months",mktime(0, 0, 0, $date2[1], $date2[0], $date2[2])));

    $sql  = "INSERT INTO boleto(nome_boleto,data_inclusao,vencimento,valor_boleto,descricao,pago,nParcela, dataparcela) 
             VALUES ('$boleto', '$dtpgto', '$timestamp', '$pagamento', '$descricao', '$pago', '$nParcela', **'$dataParcela'**)";

  }
    
05.06.2017 / 21:29