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.