When checking the insert mounted on PHP with the form information, I can see that the value of the data_final
field is not captured correctly, I would like to know what is wrong, a matter of formats.
Thanks in advance for your suggestions.
function that results in data_final
:
function calcula(){
var periodo = document.getElementsByName("periodo")[0].value;
var dt1 = document.getElementsByName("datahora_inicial")[0].value;
var val_t = document.getElementsByName("f")[0].value;
var parametros = {
method: "GET"
};
fetch("php/calcula.php?periodo=" + periodo + "&dt1=" + dt1 + "&val_t=" + val_t, parametros).then(function(resposta) {
return resposta.json();
}).then(function(retorno){
console.log(retorno)
document.getElementById("dtfim").value = retorno;
});
}
<label class="col-sm-2 col-sm-2 control-label">Fim</label>//campo data
<div class="col-md-5">
<input type="text" class="form-control round-input" name="datahora_final" required="required" id="dtfim" onchange="verifica();" value="" disabled="disabled">
</div>
insere.php
$datahora_final = $_POST['datahora_final'];
$datahora_final = date('Y-m-d H:i:s', $datahora_final);
$sql = "INSERT INTO tabela(data_fim) VALUES ('$datahora_final')";
//Ao inserir, sql da data retorna este valor:
'1970-01-01 01:00:00'
e o seguinte erro:
Undefined index: datahora_final