Jump to content

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


Malkavbug

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
Link to comment
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.
Link to comment
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
Link to comment
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.