Results 1 to 4 of 4

Thread: Inserting date into database

  1. #1
    Join Date
    Jul 2009
    Posts
    127

    Inserting date into database

    Hi
    I am trying a simple example in php. I have designed a form, when the user registers, I try to create their joining date.
    Code:
    CREATE TABLE Users
    (
    	usrnm varchar(15) NOT NULL,
    	regdate datetime default NULL
    )
    then the sql gets that value
    Code:
    $sql = "INSERT INTO Users (usrnm, regdate)
    VALUES ('".$usrnm."' , '".NOW()."')";
    The error I am getting is
    Code:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
    I think this is because I may have created a wrong syntax. Please help. Any advice on this.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Inserting date into database

    Hi
    You have done a small mistake in your syntax forming, you have
    $sql = "INSERT INTO Users (usrnm, regdate)
    VALUES ('".$usrnm."' , '".NOW()."')";
    It should be
    Code:
    $sql = "INSERT INTO `Users` (`usrnm`, `regdate`)
    VALUES ('" . $usrnm . "', NOW())";
    Please correct the mistake.

  3. #3
    Join Date
    Jul 2009
    Posts
    127

    Re: Inserting date into database

    Hi
    I am blind, sorry for the mistake. I have corrected this but the error is still there. This is how I have modified it
    Code:
    $sql = "INSERT INTO Users (usnm, firstName, lastName, emailaddress, password, passwordsalt, registrationIP, regdate)
    VALUES ('".$usrnm."' , '".$firstname."' , '".$lastname."' , '".$emailaddress"' , '".$passhash."' , '".$salt."' , '".$registrationip."' , NOW())";
    As you said, the "NOW()" is right at the end. Any advice on this.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Inserting date into database

    Hi
    Code:
    $sql = "INSERT INTO Users (usnm, firstName, lastName, emailaddress, password, passwordsalt, registrationIP, regdate)
    VALUES ('".$usrnm."' , '".$firstname."' , '".$lastname."' , '".$emailaddress"' , '".$passhash."' , '".$salt."' , '".$registrationip."' , NOW())";
    This is you statement, you are missing something again, and even this time it is a simple mistake.
    Code:
    '".$emailaddress"'
    the emailaddress is missing a period. Please correct that and you program will run.

Similar Threads

  1. Replies: 5
    Last Post: 29-01-2012, 05:56 PM
  2. Baseline Column Date automatically updates Finish Date
    By Adam 1980 in forum Microsoft Project
    Replies: 3
    Last Post: 18-05-2011, 06:08 PM
  3. Inserting and retrieving images from Database
    By Ainsley in forum Software Development
    Replies: 3
    Last Post: 25-01-2010, 01:49 PM
  4. convert filemaker pro database to access database
    By Czack in forum MS Office Support
    Replies: 3
    Last Post: 15-04-2007, 01:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,008,089.64685 seconds with 16 queries