Enter time function value in mysql

1

I think my problem is simple, I'm trying to insert into the database through the time() function but it does not enter values.

Code

 $time = time();
 mysql_query("INSERT INTO posts (user_id, estabelecimento_id, opiniao, data) 
              VALUES('".$_REQUEST['user_id']."', 
                     '".$_REQUEST['id_estabelecimento']."',
                     '".$_REQUEST['opiniao']."',
                     '".$time."' ");

That way you do not insert anything into the database, I do not know what might be causing this.

Column is bigint type

    
asked by anonymous 01.03.2015 / 22:36

2 answers

1

I suggest changing the column in the database to datetime or timestamp and in your php code to use

date("Y-m-d H:i:s");

Instead of

time();
    
02.03.2015 / 00:19
1

A much more elegant solution is to change the data type of the date column as a timestamp and leave CURRENT_TIMESTAMP as default

ALTER TABLE posts MODIFY COLUMN data TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    
28.10.2015 / 21:45