2

I have a column with datetime datatype called 'updated_at' in a mysql table,where i want the current date and time.Im trying to insert a record into the mysql table from php,as follows:

mysql_query("INSERT INTO my_table (service_name,service_status,service_comment,user_name,updated_at) VALUES($service_name,$service_status,$service_comment,$user_name,$updated_at) ")

$updated_at is defined as follows:

$updated_at = date("D, d M Y H:i:s O");

But the insert is not taking place. Any way to fix this problem ?

Please help Thank You

7
  • 2
    datetime field format is mile away from "D, d M Y H:i:s O" one Commented Sep 9, 2010 at 9:03
  • however, it's not the only fault here... Commented Sep 9, 2010 at 9:04
  • @James In addition to what @Col says, you need to wrap the values in quotes. '$updated_at'... Commented Sep 9, 2010 at 9:05
  • Thanks for the reply col. What change should i make to the code ? Commented Sep 9, 2010 at 9:06
  • Inline values? C'mon, you're asking for trouble. Use parametrized query, it'll take care of quotes for you. Commented Sep 9, 2010 at 9:08

3 Answers 3

8

Use a date format that MySQL understands:

$updated_at = date('Y-m-d H:i:s');
Sign up to request clarification or add additional context in comments.

Comments

1
INSERT INTO my_table (service_name,service_status,service_comment,user_name,updated_at) VALUES($service_name,$service_status,$service_comment,$user_name,NOW())

For mode details, see reference for NOW() function.

1 Comment

do not reproduce the OP's mistakes in your answer, but rather correct them
0

date('Y-m-d H:i:s') OR use NOW() OR set default value to collumn CURRENT_TIMESTAMP

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.