Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    55
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    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.

  • #3
    New Coder
    Join Date
    Apr 2006
    Location
    Queensland Oz
    Posts
    55
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks so much GJay, that is the answer

    I had been looking at it for too long I think


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •