Jump to content


Photo

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


  • Please log in to reply
3 replies to this topic

#1 Malkavbug

Malkavbug
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 15 March 2006 - 12:42 AM

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)

$sql = "INSERT INTO members
(Handle,Password,Email,
CreateDate,RegionGroup,
AgeGroup,Sex) VALUES
('$NewHandle',password('$NewPassword'),
'$email','NOW()','$region',
'$age','$sex')";
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
'NOW()'
a value before the insert, such as
'NOW()'= "$timenow"

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


#2 Steveo31

Steveo31
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationSan Jose, CA

Posted 15 March 2006 - 02:43 AM

NOW() is a function, not a translated value, so remove the single quotes.

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

#3 Malkavbug

Malkavbug
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 15 March 2006 - 02:52 AM

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.

#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 15 March 2006 - 07:37 AM

[!--quoteo(post=355197:date=Mar 15 2006, 02:52 AM:name=Malkavbug)--][div class=\'quotetop\']QUOTE(Malkavbug @ Mar 15 2006, 02:52 AM) View Post[/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

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users