Skip to main content
Known Participant
June 9, 2011
Answered

How to insert date into updated record (MySql, PHP)

  • June 9, 2011
  • 1 reply
  • 2402 views

I want to be able to update an existing record and automatically include the date the change was made when I submit the data back to the MySql database.

I saw this thread on how to insert the date on a new record using NOW()

http://forums.adobe.com/thread/855152?decorator=print&displayFullThread=true#855152

After reading it I successfully amended my insert.php page.

Here's the code from my insert.php page which works nicely:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO standardsclient_tbl (client_name, pantone_ref1, pantone_ref1_image, font_ref1, font_ref1_image, `date`) VALUES (%s, %s, %s, %s, %s, NOW())",
                       GetSQLValueString($_POST['client_name'], "text"),
                       GetSQLValueString($_POST['pantone_ref1'], "text"),
                       GetSQLValueString($_POST['pantone_ref1_image'], "text"),
                       GetSQLValueString($_POST['font_ref1'], "text"),
                       GetSQLValueString($_POST['font_ref1_image'], "text"),
                       GetSQLValueString($_POST['date'], "date"));

This is the update.php page, I changed `date`=%s to `date`=NOW() but all this did was stop me from updating the record at all.

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE standardsclient_tbl SET client_name=%s, pantone_ref1=%s, pantone_ref1_image=%s, font_ref1=%s, font_ref1_image=%s, `date`=NOW() WHERE client_ID=%s",
                       GetSQLValueString($_POST['client_name'], "text"),
                       GetSQLValueString($_POST['pantone_ref1'], "text"),
                       GetSQLValueString($_POST['pantone_ref1_image'], "text"),
                       GetSQLValueString($_POST['font_ref1'], "text"),
                       GetSQLValueString($_POST['font_ref1_image'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['client_ID'], "int"));

Can anyone see where I've gone wrong?

Thanks

This topic has been closed for replies.
Correct answer

In update query you have 6 %s but 7 GetSQLValueString. That's your problem.

1 reply

Correct answer
June 9, 2011

In update query you have 6 %s but 7 GetSQLValueString. That's your problem.

Wookie1Author
Known Participant
June 9, 2011

Sorted thanks!