Solved

Update modified timestamp in Dreamweaver and MySQL PHP database

Posted on 2010-11-14
8
645 Views
Last Modified: 2012-05-10
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!
0
Comment
Question by:palmtreeinfotech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 

Author Comment

by:palmtreeinfotech
ID: 34133256

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

0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34133262
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?

0
 

Author Comment

by:palmtreeinfotech
ID: 34133279
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.
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:palmtreeinfotech
ID: 34133289
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.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34133291
Hang on, will post screenshots momentarily.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 34133318
Okay, steps:

1. Log into phpmyadmin

(steps 2-4 refer to image 1)
2. Click on the table you want to modify on the left menu
3. If you are not taken to the Structure tab after step 2, click on it now.
4. Click the pencil icon in the column you want to modify

For steps 2-4
5. Set the values as I have it in image2 (substituting your name for the column, obviously)

Step 5
6. Change the Update Record behavior so you are not updating that column via form submission anymore.

That's it.
0
 

Author Closing Comment

by:palmtreeinfotech
ID: 34133344
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!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34133350
You're welcome.  Glad this one went faster than the other one did :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to hide contact form only if no validation errors 4 63
Export Data from MySql Using PHP 16 65
Mysql query one to many 11 37
Last 4 numbers of a variable 9 20
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Creating and Managing Databases with phpMyAdmin in cPanel.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question