How to insert today's date and time by default and send the same date to the PHP page

-1

I'm doing a project and for this email form I need the current date and time to appear by default (automatically). And then I want to receive this data on the PHP page. How can I do this, can anyone help me?

This is my form code:

<input name="data-atual" id="data-atual" style="position:absolute;left:2px;top:75px; font-family:Ebrima; font-weight:bold?; color: bold?; font-size:9pt; width:203px; height:20px;" type="date" value="Agora()" >
    
asked by anonymous 04.06.2018 / 15:32

2 answers

0

You can put the code:

<?php echo date(); ?>

Your INPUT would look like this:

<input name="data-atual" id="data-atual" style="position:absolute;left:2px;top:75px; font-family:Ebrima; font-weight:bold?; color: bold?; font-size:9pt; width:203px; height:20px;" type="date" value="<?php echo date(); ?>" >
    
04.06.2018 / 15:38
0
  

Your page and registration

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script></head><?phpdate_default_timezone_set('America/Sao_Paulo');$data_hora=date("d-m-Y H:i:s");
?>
<input type="text" name="data_hora" id="data_hora" value="<?php echo $data_hora ?>">
<button type="button" onclick="enviarCad()">Enviar Cadastro</button>

<script type="text/javascript">
  function enviarCad(){
    var dt_hora = $('#data_hora').val();
    $.ajax({
      type: 'POST',
      data: 'dt_hora='+dt_hora,
      url: 'insere_cadastro.php',
      success: function(data){
        alert(data);
      }
    });    
  }
</script>

Page inserts into the bank

  

insere_cadastro.php

 <?php 
     include "conexao.php";
    $dt_hora = $_POST['dt_hora'];
    //Você precisa formatar a data que vem para inserir no banco

    /*
    Monta seu sql para inserir
    */
     ?>

Remembering that one advantage of using Ajax is that it will not refresh the page.

Here is a similar tutorial link

    
06.06.2018 / 14:37