PHP/SQL datatype problem error?

Discussion in 'Programming' started by komirad, Aug 24, 2007.

  1. #1
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '04:47:41)' at line 1
    HTML:
    This happens when I try to insert the date/time into the database when registering a user.

    $registration_date = gmdate('Y-m-d H:i:s');
    
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "registrationForm")) {
      $insertSQL = sprintf("INSERT INTO sc_users (user_name, user_pass, user_email, user_registered) VALUES (%s, %s, %s, %s)",
                           GetSQLValueString($_POST['username'], "text"),
                           GetSQLValueString($_POST['password1'], "text"),
                           GetSQLValueString($_POST['email'], "text"),
    					   $registration_date);
    Code (markup):
    my datatype in a SQL database is datetime

    THANKS FOR HELPING :D
     
    komirad, Aug 24, 2007 IP
  2. Tarkan

    Tarkan Peon

    Messages:
    491
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    When you use %s, you have to do this when in an INSERT query:
    '%s' <---- the single quotes are important.
    Also if your value is just a number, simply use %d WITHOUT single quotes.
     
    Tarkan, Aug 24, 2007 IP
  3. komirad

    komirad Well-Known Member

    Messages:
    921
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Its a generated code from dreamweaver, but i changed the date part, so I guess changing to %d should work.

    :)
     
    komirad, Aug 24, 2007 IP
  4. Tarkan

    Tarkan Peon

    Messages:
    491
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try both ways :D.
     
    Tarkan, Aug 24, 2007 IP