Jump to content

Archived

This topic is now archived and is closed to further replies.

Malkavbug

now() function used to INSERT datetime into database column?

Recommended Posts

Hit an odd issue tonight, and really am too tired to start to dig for an answer. Basically a datetime issue.

Also, I appreciate any replies, and in the name of me trying to learn how this works could you please explain why it isn't working, not just how to fix it? I would greatly appreciate it.

Here is the code (respaced and all for these forums)

[code]$sql = "INSERT INTO members
(Handle,Password,Email,
CreateDate,RegionGroup,
AgeGroup,Sex) VALUES
('$NewHandle',password('$NewPassword'),
'$email','NOW()','$region',
'$age','$sex')";
[/code]
DB Side (MySQL) I am at
CreateDate datetime Not Null default = 0000-00-00 00:00:00

All other columns are inputing correctly, except CreateDate, which is just entering the defauly value of 0000-00-00 00:00:00

Probably as simple as giving [code]'NOW()'[/code] a value before the insert, such as [code]'NOW()'= "$timenow"[/code]

or it could just be some issue with me having it in upper case.

Either way, brain fried for tonight, just glad the account creation portion is working.

Also, if you know off the top of your head now to grab the users IP addess and assign it to a variable it would be much appreciated (same deal, want to into it into a column) :P

Share this post


Link to post
Share on other sites
NOW() is a function, not a translated value, so remove the single quotes.

INSERT INTO table VALUES('something', 'other value', NOW(), 'other values);

Share this post


Link to post
Share on other sites
Fixed it. you rock! :P I image it is the same deal with the inserting the users IP address once I find that function (assuming there is a function for this, trying to dig for it myself)

I really appreciate the help, it was driving me nuts. So any functions being inserted do not need quotes around them, only variables.

Share this post


Link to post
Share on other sites
[!--quoteo(post=355197:date=Mar 15 2006, 02:52 AM:name=Malkavbug)--][div class=\'quotetop\']QUOTE(Malkavbug @ Mar 15 2006, 02:52 AM) [snapback]355197[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Fixed it. you rock! :P I image it is the same deal with the inserting the users IP address once I find that function (assuming there is a function for this, trying to dig for it myself)

I really appreciate the help, it was driving me nuts. So any functions being inserted do not need quotes around them, only variables.
[/quote]

Anything that is a string would get quotes around them, but if you had $x = 10, insert into tblHi(id) values ($x) would work. Functions do not, because then they don't get evaluated. :D

Share this post


Link to post
Share on other sites

×

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.