Inserting current date in php

0

I'm trying to insert the current date as the person registers but did not want the user to report this data but rather to insert it through some function with mysql to record the date the vendor was registered. But I tried in some ways and I could not, I looked here in the forum and also I could not then I created the question

<?php  
        if(isset($_POST['enviar_for'])){

                $id = $_POST['id'];
                $fornecedor = $_POST['fornecedor'];
                $observacoes = $_POST['observacoes'];
                $data_cadastro = date('Y-m-d', strtotime($_POST['data_cadastro']));

                $sql = "SELECT * FROM cadfor WHERE id_pessoa = '$id' "; 
                $resulta = $conn->query($sql);
                $row = $resulta->fetch_assoc();

                if ($resulta->num_rows > 0 ){
                    $result_endereco = "UPDATE cadfor SET tipo_endereco = '$tipo_endereco', cep = '$cep ', tipo_logr = '$tipo_logr', nome_logr = '$nome_logr', nume_logr = '$nume_logr', comp_logr = '$comp_logr', cidade = '$cidade', bairro = '$bairro', uf = '$uf' WHERE id_pessoa = '$id' ";
                } else {
                    $result_endereco = "INSERT INTO cadfor(id_pessoa, fornecedor, observacoes, data_cadastro) VALUES ('$id', '$fornecedor', '$observacoes', 'NOW()' )";
                }
                $resultado = mysqli_query($conn, $result_endereco);
                echo $result_endereco;
        }
  ?>
    
asked by anonymous 19.10.2017 / 18:43

3 answers

2

The NOW() function of MySQL returns the current date.

You can do this:

$result_endereco = "INSERT INTO cadfor(id_pessoa, fornecedor, observacoes, data_cadastro) VALUES ('$id', '$fornecedor', '$observacoes', NOW())";

To work, the data_cadastro column must be of type DATE, DATETIME, or TIMESTAMP.

    
19.10.2017 / 18:52
3

You can use the date() function of php by passing the format you want.

date('Y-m-d H:i:s');
    
19.10.2017 / 18:49
0

You can use this:

date('Y-m-d H:i:s');
    
19.10.2017 / 18:55