4
People, I need to convert the data format of my form fields to save in my database. As the data is coming from the form by array I am not able to capture them and convert before recording. The date field is in my form identified as "maturity[]" and with mask in the format 00/00/0000 then when I receive I need to convert it to 0000/00/00. The value field is in my form as "value[]" with a coin mask 1,000.00 but I need to convert it to 1000.00. I have tried to do the conversion before and also inside the loop but gives error.
$valorparc = $_POST['valor'];
$data_vctoparcela = $_POST['vencimento'];
$quant_linhas = count($_POST['valor']);
for ($i=0; $i<$quant_linhas; $i++) {
$data = $data_vctoparcela[$i];
$valorp = $valorparc[$i];
mysql_query("INSERT INTO lc_parcelas (ID,cod_cliente,id_fatura,valor_parcela,data_vcto,parcela)
VALUES('".$idEMP."','".$cod_cliente."','".$id_fatura."','".$valorp."','".$data."','".$i."')") or die (mysql_error());
}
specify the form appropriately.. You don’t know what 00/00 .. The stretch 0000, by deduction is the year. But what is the position of the month and day? Example yyyy/mm/dd
– Daniel Omine
in the form: dd/mm/yyyy but in mysql you have to write yyyy/mm/dd
– Marcos A. Silva
in mysql, it normally uses the default iso8601 yyyy-mm-dd.. but depending on the version it also accepts / (bar)
– Daniel Omine
in the form, the user inserts the date freely? is an input text field? it is safer and simpler to set a select field for day, another for month and another for year.
– Daniel Omine
Opa brother do not know if it will suit you !!! more look if you can implement this class to your code !! Class link of a look here !
– user36056
Daniel, sorry my error, in mysql is yyyy-mm-dd same
– Marcos A. Silva