Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/256120-now-function/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312963
Share on other sites

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.  :D  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!

Link to comment
https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312964
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/256120-now-function/#findComment-1312967
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.