how to insert the current timestamp into mysql db using a php insert query

In my database (mysql), i have a table with structure - username - varchar insert_time - timestamp

this table was created in mysql using the phpmyadmin tool, and for the insert_time column, i have mentioned default value as 0000-00-00 00:00:00.

Now the problem is, i have to update this default value with the current timestamp later on, using a php script.

I tried doing this - CODE:PHP

$update_query = 'UPDATE db.tablename SET insert_time=now() WHERE username=' .$somename;

when the php script is run, it fails, and is unable to insert anything into the database.

Please let me know where i'm doing wrong. Thanks.

This question and answers originated from www.stackoverflow.com
Question by (5/20/2011 6:04:47 PM)

Answer

What error message are you getting?

I'd guess your actual error is because your php variable isn't wrapped in quotes. Try this

$update_query = "UPDATE db.tablename SET insert_time=now() WHERE username='" .$somename . "'";

Answer by

Find More Answers
Related Topics  php  mysql  update  timestamp  current
Related Questions