Skip to main content
Participant
May 4, 2011
Question

How can I insert date into MySQL table?

  • May 4, 2011
  • 1 reply
  • 950 views

I am having a lot of bother getting the date to insert into the MySQL table. The code generated by Dreamweaver CS4 (part of it) is:

$insertSQL = sprintf("INSERT INTO content (RegionName, `Intro Text`, Content, Photo, Title, Price) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['Region'], "text"),
                       GetSQLValueString($_POST['IntroText'], "text"),
                       GetSQLValueString($_POST['FullContent'], "text"),
                       GetSQLValueString($_POST['Photo'], "text"),
                       GetSQLValueString($_POST['Title'], "text"),
                       GetSQLValueString($_POST['Price'], "double"));

  mysql_select_db($database_vcb, $vcb);
  $Result1 = mysql_query($insertSQL, $vcb) or die(mysql_error());
}

I have searched and found posts about using DATETIME but what confuses me is when I find solutions that posr handwritten PHP code because I do not know how to incorporate this into the code that is written by Dreamweaver. What I need is to have the date that the record was added into the database.

This topic has been closed for replies.

1 reply

Participating Frequently
May 5, 2011

Hey,

you have to add another column, for example "date". The MySQL-Funktion "now()" returns the datetime-Value.