Inserting current time into a database.

Discussion in 'PHP' started by pictureboarduk, Dec 8, 2009.

  1. #1
    Hi,

    I'm making a simple forum.

    When a user register's, I trying to create their join date.

    
    CREATE TABLE Users
    (
    	userName varchar(15) NOT NULL,
    	registrationDate datetime default NULL
    )
    
    Code (markup):
    and then have MySQL automatically set that value:

    
    $sql = "INSERT INTO Users (userName, registrationDate)
    VALUES ('".$username."' , '".NOW()."')";
    
    Code (markup):
    The program keeps failing though. when the PHP code is ran it says:

    Am I doing this right?

    I think it may be my syntax, but I could be wrong.

    Appreciate all help with this. :)
     
    pictureboarduk, Dec 8, 2009 IP
  2. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #2
    Try:
    $sql = "INSERT INTO `Users` (`userName`, `registrationDate`)
    VALUES ('" . $username . "', NOW())";
    PHP:
     
    CoreyPeerFly, Dec 8, 2009 IP
    pictureboarduk likes this.
  3. pictureboarduk

    pictureboarduk Well-Known Member

    Messages:
    551
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Hey thanks for helping.

    Am I blind? But my actual line looks the same as yours, but it still keeps on saying it.

    
    $sql = "INSERT INTO Users (userName, firstName, lastName, emailaddress, password, passwordsalt, registrationIP, registrationDate)
    VALUES ('".$username."' , '".$firstname."' , '".$lastname."' , '".$emailaddress"' , '".$passhash."' , '".$salt."' , '".$registrationip."' , NOW())";
    
    Code (markup):
    The NOW() is right at the end.

    +ve rep's, thanks!
     
    pictureboarduk, Dec 8, 2009 IP
  4. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #4
    '".$emailaddress"'
    PHP:
    is missing a period.
     
    CoreyPeerFly, Dec 8, 2009 IP
  5. pictureboarduk

    pictureboarduk Well-Known Member

    Messages:
    551
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    #5
    You rock Coreye!!!!!!!

    Thanks so much buddy, I did go blind!

    Program working now! :)

    thumbsup.jpg
     
    pictureboarduk, Dec 8, 2009 IP