Avatar of palmtreeinfotech
palmtreeinfotech
Flag for United States of America asked on

Update modified timestamp in Dreamweaver and MySQL PHP database

Hello experts!  I have an update page where I want the current timestamp updated in the database when the user presses the submit button.  I have the update page and it's working (thanks to another expert in the Dreamweaver area).  I have a hidden field that is set to update field [modified] in the database table.

My question is what do I put in the hidden field (called hiddenmodified) in the Value field?  I'm trying now() and timestamp() but it's not working.

On the update record behavior I am telling Dreamweaver that this field is to update to [modified] field in database but I think I'm just not knowing what to put there in the Value field of the hidden field on my form.

In my table structure I have this set to timestamp.
Thank you experts!
PHPAdobe DreamweaverMySQL Server

Avatar of undefined
Last Comment
Jason C. Levine

8/22/2022 - Mon
palmtreeinfotech

ASKER

Partial code below showing hidden form field with current value:

<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
  <table width="100%" border="1" cellpadding="2" cellspacing="2">
    <tr>
      <td>ID:</td>
      <td><label for="ID"></label>
        <?php echo $row_Recordset1['ID']; ?></td>
    </tr>
    <tr>
      <td width="22%">Date Added:
      <input name="hiddenmodified" type="hidden" id="hiddenmodified" value="CURRENT_TIMESTAMP" />
      <input name="ID" type="hidden" id="ID" value="<?php echo $row_Recordset1['ID']; ?>" /></td>
      <td width="78%"><label for="dateadded"></label>
        <?php echo $row_Recordset1['Date_Added']; ?></td>
    </tr>
    <tr>
      <td>Date Last Modified:</td>
      <td><label for="datemodified"></label>
        <?php echo $row_Recordset1['Modified']; ?></td>

The rest of my update query here...
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE tblInfo SET Modified=%s, Bus_Name=%s, Contact_Name=%s, Address=%s, City=%s, `State`=%s, Zip=%s, Phone=%s, Fax=%s, Email=%s, Website=%s, Active=%s, Bus_Month=%s, Bus_Year=%s, Comments=%s WHERE ID=%s",
                       GetSQLValueString($_POST['hiddenmodified'], "date"),
                       GetSQLValueString($_POST['busname'], "text"),
                       GetSQLValueString($_POST['contactname'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['city'], "text"),
                       GetSQLValueString($_POST['state'], "text"),
                       GetSQLValueString($_POST['zip'], "text"),
                       GetSQLValueString($_POST['phone'], "text"),
                       GetSQLValueString($_POST['fax'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['website'], "text"),
                       GetSQLValueString($_POST['status'], "int"),
                       GetSQLValueString($_POST['bommonth'], "text"),
                       GetSQLValueString($_POST['bomyear'], "text"),
                       GetSQLValueString($_POST['comments'], "text"),
                       GetSQLValueString($_POST['ID'], "int"));

Open in new window

Jason C. Levine

Hi again, palmtreeinfotech

>> My question is what do I put in the hidden field (called hiddenmodified) in the Value field?  I'm trying
>> now() and timestamp() but it's not working.

Don't put anything in the value field.  Instead, you configure the MySQL column to be an auto-updating timestamp field.  

How do you touch the MySQL configuration?  Command line?  phpMyAdmin?

palmtreeinfotech

ASKER
Hi JASON!  Wow you're the expert in all the fields that's great!  Hmm..Yeah I have phpmyAdmin.  I don't know how to set it to auto-update though from there.  I'm looking at the table structure and can't see anything regarding auto update in the table.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
palmtreeinfotech

ASKER
OMG Jason, I just left the field blank and it seems to work.  Geez you need to work for me! LOL thanks again for your quick reply.
Jason C. Levine

Hang on, will post screenshots momentarily.
ASKER CERTIFIED SOLUTION
Jason C. Levine

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
palmtreeinfotech

ASKER
Jason, thank you so much for screenshots.  I took out the default and made the timestamp varilable in the table and now it works!  Genius and thanks again!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jason C. Levine

You're welcome.  Glad this one went faster than the other one did :)