Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-03-2006, 12:03 AM   PM User | #1
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
How do I insert current date into mySQL?

I have a table, new, with fields id, member, datein, dateout

Can anyone tell me why this won't work

if ($submit) {
$sql = "INSERT INTO new VALUES('','$member','curdate()','date_add(now(), interval 1 year)')";
$result = mysql_query($sql);
if ($result) {
echo "Done";
exit();
}
}

yet this does work

if ($submit) {
$sql = "INSERT INTO new VALUES('','$member','','')";
$result = mysql_query($sql);
if ($result) {
$sql = "UPDATE new SET datein=curdate(), dateout=date_add(now(), interval 1 year) WHERE member='$member'";
$result = mysql_query($sql);
echo "Done";
exit();
}
}

Any help appreciated
ozlad is offline   Reply With Quote
Old 05-03-2006, 12:11 AM   PM User | #2
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
because cur_date and date_add are 'functions', I don't think they should be in the single-quotes, as that will mean they get treated as strings- not a valid date-time format.
GJay is offline   Reply With Quote
Old 05-03-2006, 12:48 AM   PM User | #3
ozlad
New Coder

 
Join Date: Apr 2006
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
ozlad is an unknown quantity at this point
Thanks so much GJay, that is the answer

I had been looking at it for too long I think
ozlad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:06 AM.


Advertisement
Log in to turn off these ads.