Insert time function value in mysql

Asked

Viewed 142 times

1

I think my problem is simple, I’m trying to insert into the database through the function time() but does not insert 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 it doesn’t enter anything into the database, I don’t know what could be causing it.

The column is with type bigint

  • the column data is of which type in the bank?

  • It’s kind of bigint

  • 1

    Leave your Insert like this and see the error: mysql_query('inser....') or die(mysql_error());.

2 answers

1

I suggest to change 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();

1

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

ALTER TABLE posts MODIFY COLUMN data TIMESTAMP DEFAULT CURRENT_TIMESTAMP

Browser other questions tagged

You are not signed in. Login or sign up in order to post.