I'm using a mysql_query() in PHP to insert a value into a table in a database. One of the attributes of that table is "timestamp" which is supposed to be the current time that the query was made. How can I generate this? I tried using "time()" in PHP, but this is not inserting开发者_Python百科 correctly in the query. When I insert what the time() function generates, it shows up as a default in my table, as: "0000-00-00 00:00:00". How can I generate the current time in order to input it into my table?
In your query, you need to set the value of that field to NOW() which is MySQL's function for getting a timestamp of the current time.
If you put your actual query in your question, I can help you with a more specific answer ;)
insert into table (datetime_field) values (now())
php function time() returns a unix timestamp that it's an integer value.
Go to php.net and view the codes for getting date and time and check whether you typed the codes correctly. If you did, then check if the format you are using in your code is similar to the one you are using in your table.
精彩评论