how to insert the current timestamp into mysql db using a php insert query
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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 arun nair (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 Ash Burlaczenko
Find More Answers