0
When checking the mounted Insert PHP with the form information, I can understand the value of the field data_final
is not captured correctly, I would like to know what is wrong, because I believe it is a matter of formats.
Thanks in advance for the suggestions.
function that results in the 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>
php insert.
$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
A
var_dump($_POST['datahora_final'])
returns what?– Inkeliz
The same I quoted above
– R.Gasparin
Your code seems to be incomplete, or completely confused. In Javascript code you make a GET request to the file
calcula.php
, but you presented the code ofinsere.php
that is not called in the passage presented and gets the values in$_POST
. The very functioncalcula
Javascript is not called in the code shown, but a functionverifica
, that was not presented, is called in the eventonchange
ofinput
. You quote the fielddata_final
and in the code there isdatahora_final
; they are the same field or you have not posted the excerpt that contains the first?– Woss