When entering, value is incorrect

0

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
    
asked by anonymous 20.05.2017 / 02:23

1 answer

1

If the datetime_final field is being filled with date in 05/20/2017 format then the problem is in date('Y-m-d H:i:s', $datahora_final) do so:

$datahora_final_sem_formatar   = $_POST['datahora_final'];
$datahora_final   = substr($datahora_final_sem_formatar,6,4) . "-" . substr($datahora_final_sem_formatar,3,2) . "-" . substr($datahora_final_sem_formatar,0,2);
    
20.05.2017 / 19:39