Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Jun 09, 2011 Jun 09, 2011

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

TOPICS
Server side applications
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Jun 09, 2011 Jun 09, 2011

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

Translate
Guest
Jun 09, 2011 Jun 09, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2011 Jun 09, 2011
LATEST

Sorted thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines