DonaldFaulknor Posted January 31, 2012 Share Posted January 31, 2012 wow, this was the first website EVER that required a Google search in order to register. Anyways... What reason does now() function not work in MySql 5 and how can I get it to work? Most sources online will say you can set now() as default for a datetime field, but that's incorrect, you can't. Also, I've tried inserting it through php, which also didn't work. mysql_query("INSERT INTO table_name(field1, field2, whens) VALUES('$value1','$value2','now()')"); mind you, in this sql query, field1, and field2 ARE properly inserting, so it's not an issue with connecting to the database or inserting in general. The values are passed from a form. I have tried also passing the now() function through the form, that also didn't work. Would appreciate some help. Thank You. Quote Link to comment https://forums.phpfreaks.com/topic/256120-now-function/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 31, 2012 Share Posted January 31, 2012 By putting now() inside of single-quotes in the query statement, it becomes literal string data that consists of the characters - n, o, w, (, and ). For it to be treated as the mysql now() function name, it would not be surrounded by single-quotes inside the query statement. Quote Link to comment https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312963 Share on other sites More sharing options...
DonaldFaulknor Posted January 31, 2012 Author Share Posted January 31, 2012 Thank you thank you very much. That worked. What's been frustrating me for 4 hours was solved in a few minutes on this forum. Trust me, I'll be back. Hopefully to help others out. I hope you have a wonderful day. By the way, the verification questions, require some to search Google lol, like me. I didn't know Rasmus' last name, just like I have to search Google for John, George, Paul, and ..... Someone should tell the site administrator to make them more simple, like, what is 5 plus 2 or something. lol. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312964 Share on other sites More sharing options...
ManiacDan Posted January 31, 2012 Share Posted January 31, 2012 I believe the questions are designed to show you how easy it is to find simple information on google, so you don't ask us to do it for you. Also, to address something in your first post: Creating a timestamp field with the default value CURRENT_TIMESTAMP. The function NOW() is used to return the current timestamp inside queries, but CURRENT_TIMESTAMP is the mysql command for defaults. See the manual for more. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.