1
I have an HTML form that, after being filled in, the values of the fields are sent via POST method to a PHP file and this file captures these values by sending to the Mysql database.
My problem lies in the calculation of installment accounts. If I make a purchase in installments 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 up to 4 further installments. That is, if the first installment is day 05/06/2017, the next 4 installments would be: 05/07, 05/08, 05/09 and 05/10/2017. The problem that when executing the form, it returns a blank page and does not save anything in Mysql. Connections are correct, there is return of PHP errors in case of code error and etc.
Follow the stretch for assistance:
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 have a field (Installments?) if yes, enter this condition, if not enter another.
Follows 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 one echo
at the end of for
, he returns what I put in him.
Within the
for
, try to putif(!$stm) { die($conexao->errorInfo()); }
to see if there are any mistakes.– Woss
the return of
strtotime
returns atimestamp
. If maturity is of the date type you will need to convert thetimestamp
in the correct format. Using$timestamp = date ('Y-m-d',$timestamp );
– Don't Panic