mysql time stamp

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bkchf123
Forum Newbie
Posts: 11
Joined: Mon Jan 25, 2010 3:01 pm

mysql time stamp

Post by bkchf123 »

i have a table for specials

Code: Select all

 
mysql_query("CREATE TABLE specials (
id int(11) NOT NULL auto_increment,
specialName varchar(255) NOT NULL,
createdBy varchar(255) NOT NULL,
updatedBy varchar(255) NOT NULL,
email varchar(255) NOT NULL,
removeOn varchar(255) NOT NULL,
date_added timestamp NOT NULL default CURRENT_TIMESTAMP,
date_updated NOW(),
 
 
everytime a person adds special the date_added column adds the date time n/p
now when they update that column i want the dateupdated to add time date automatically timestamp only works once
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: mysql time stamp

Post by JakeJ »

mysql_query("UPDATE specials set date_updated = 'now()'"); <-- note the single quote then the double quote between the closing parenthesis.
bkchf123
Forum Newbie
Posts: 11
Joined: Mon Jan 25, 2010 3:01 pm

Re: mysql time stamp

Post by bkchf123 »

JakeJ wrote:mysql_query("UPDATE specials set date_updated = 'now()'"); <-- note the single quote then the double quote between the closing parenthesis.

Code: Select all

 
<?php require_once('../Connections/BrowardLimo.php'); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
$Paramid_WADAspecials = "-1";
if (isset($_GET['id'])) {
  $Paramid_WADAspecials = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_BrowardLimo, $BrowardLimo);
$query_WADAspecials = sprintf("SELECT id, specialName, createdBy, updatedBy, email, removeOn, date_added, comment FROM specials WHERE id = %s", GetSQLValueString($Paramid_WADAspecials, "int"));
$WADAspecials = mysql_query($query_WADAspecials, $BrowardLimo) or die(mysql_error());
$row_WADAspecials = mysql_fetch_assoc($WADAspecials);
$totalRows_WADAspecials = mysql_num_rows($WADAspecials);?>
<?php 
// WA Application Builder Update
if (isset($_POST["Update_x"])) // Trigger
{
  $WA_connection = $BrowardLimo;
  $WA_table = "specials";
  $WA_redirectURL = "specials_Detail.php?id=".((isset($_POST["WADAUpdateRecordID"]))?$_POST["WADAUpdateRecordID"]:"")  ."";
  $WA_keepQueryString = false;
  $WA_indexField = "id";
  $WA_fieldNamesStr = "specialName|updatedBy|email|removeOn|comment";
  $WA_fieldValuesStr = "".((isset($_POST["specialName"]))?$_POST["specialName"]:"")  ."" . "|" . "".((isset($_POST["updatedBy"]))?$_POST["updatedBy"]:"")  ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"")  ."" . "|" . "".((isset($_POST["removeOn"]))?$_POST["removeOn"]:"")  ."" . "|" . "".((isset($_POST["comment"]))?$_POST["comment"]:"")  ."";
  $WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|',none,''";
  $WA_comparisonStr = " LIKE | LIKE | LIKE | LIKE | LIKE ";
  $WA_fieldNames = explode("|", $WA_fieldNamesStr);
  $WA_fieldValues = explode("|", $WA_fieldValuesStr);
  $WA_columns = explode("|", $WA_columnTypesStr);
  
  $WA_where_fieldValuesStr = "".((isset($_POST["WADAUpdateRecordID"]))?$_POST["WADAUpdateRecordID"]:"")  ."";
  $WA_where_columnTypesStr = "none,none,NULL";
  $WA_where_comparisonStr = "=";
  $WA_where_fieldNames = explode("|", $WA_indexField);
  $WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
  $WA_where_columns = explode("|", $WA_where_columnTypesStr);
  $WA_where_comparisons = explode("|", $WA_where_comparisonStr);
  
  $WA_connectionDB = $database_BrowardLimo;
  mysql_select_db($WA_connectionDB, $WA_connection);
  if (!session_id()) session_start();
  $updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
  $WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues,  $WA_where_comparisons );
  $WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
  $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
  if ($WA_redirectURL != "")  {
    if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
      $WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
    }
    header("Location: ".$WA_redirectURL);
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Caracole" />
<title>admin</title>
<link href="favicon.ico" type="image/x-icon" rel="icon" />
    <link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <link rel="stylesheet" type="text/css" href="../css/tripoli.simple.css" media="screen, projection, print" />
    <link rel="stylesheet" type="text/css" href="../css/layout.css" media="screen, projection, print" />
<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<script type="text/javascript">
        //<![CDATA[
        document.write('<link rel="stylesheet" type="text/css" href="../css/js/js.css" media="screen, projection, print" />');
        //]]>
    </script>
    <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="../css/ie/ie.css" media="screen, projection, print" />
    <![endif]-->
    <!--[if lt IE 7]>
    <script src="js/DD_belatedPNG_0.0.7a-min.js" type="text/javascript"></script>
    <script>
        DD_belatedPNG.fix(' #header, h1, h1 a, .close, .field,.paginate .current, .icon, .required-icon, .search input');
    </script>
    <link rel="stylesheet" href="../css/ie/ie6.css" type="text/css" media="screen, projection"/>
    <![endif]-->
<link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>
<body>
 
<!-- Header -->
<!-- InstanceBeginEditable name="top" -->
<div id="header">
  <div class="container content">
    <h1><a href="../index.php" title="Back to home">Titanium</a></h1>
    <a href="http://www.pixelastic.com/" target="_blank" class="viewWebsite"><span>View website</span></a>
    <div class="loginInfos"> You're logged in as <strong>Admin</strong>. <a href="#" title="Edit your settings">Edit your settings</a>, or <a href="#" title="Log out">Log out</a></div>
  </div>
</div>
<!-- InstanceEndEditable -->
<!-- /Header -->
 
<!-- Global -->
<div id="page-content">
<!-- Sidebar -->
<!-- InstanceBeginEditable name="nav" -->
<ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a href="specials_Results.php">Specials</a></li>
  <li><a href="email_Results.php">Email</a></li>
  <li><a href="#">test</a></li>
  <li><a href="#">Item 3.2</a></li>
  <li><a href="#">Item 3.3</a></li>
</ul>
<!-- InstanceEndEditable -->
<!-- /Sidebar -->
<!-- InstanceBeginEditable name="mainContent" -->
<div class="admincontainer">
 
 
<div class="WADAUpdateContainer">
  <?php if ($totalRows_WADAspecials > 0) { // Show if recordset not empty ?>
    <form action="specials_Update.php?id=<?php echo(rawurlencode($row_WADAspecials['id'])); ?>" method="post" name="WADAUpdateForm" id="WADAUpdateForm">
      <div class="WADAHeader">Update Record</div>
      <div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
      <table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <th class="WADADataTableHeader">specialName:</th>
          <td class="WADADataTableCell"><input type="text" name="specialName" id="specialName" value="<?php echo(str_replace('"', '"', $row_WADAspecials['specialName'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">createdBy:</th>
          <td class="WADADataTableCell"><?php echo(str_replace('"', '"', $row_WADAspecials['createdBy'])); ?></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">updatedBy:</th>
          <td class="WADADataTableCell"><input type="text" name="updatedBy" id="updatedBy" value="<?php echo(str_replace('"', '"', $row_WADAspecials['updatedBy'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">email:</th>
          <td class="WADADataTableCell"><input type="text" name="email" id="email" value="<?php echo(str_replace('"', '"', $row_WADAspecials['email'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">removeOn:</th>
          <td class="WADADataTableCell"><input type="text" name="removeOn" id="removeOn" value="<?php echo(str_replace('"', '"', $row_WADAspecials['removeOn'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">date_added:</th>
          <td class="WADADataTableCell"><?php echo(str_replace('"', '"', $row_WADAspecials['date_added'])); ?></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">comment:</th>
          <td class="WADADataTableCell"><textarea name="comment" id="comment" cols="32"><?php echo(str_replace('"', '"', $row_WADAspecials['comment'])); ?></textarea></td>
        </tr>
      </table>
      <div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
      <div class="WADAButtonRow">
        <table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Update" id="Update" value="Update" alt="Update" src="../WA_DataAssist/images/Pacifica/Traditional_update.gif"  /></td>
            <td class="WADADataNavButtonCell" nowrap="nowrap"><a href="specials_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Pacifica/Traditional_cancel.gif" /></a></td>
          </tr>
        </table>
        <input name="WADAUpdateRecordID" type="hidden" id="WADAUpdateRecordID" value="<?php echo(rawurlencode($row_WADAspecials['id'])); ?>" />
      </div>
    </form>
  <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_WADAspecials == 0) { // Show if recordset empty ?>
    <div class="WADANoResults">
      <div class="WADANoResultsMessage">No record found.</div>
    </div>
  <?php } // Show if recordset empty ?>
</div>
</div>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="footer" -->
<div id="footer">footer</div>
<!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
//-->
        </script>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($WADAspecials);
?>
 
here is the code for that page where do I put it
bkchf123
Forum Newbie
Posts: 11
Joined: Mon Jan 25, 2010 3:01 pm

Re: mysql time stamp

Post by bkchf123 »

bkchf123 wrote:
JakeJ wrote:mysql_query("UPDATE specials set date_updated = 'now()'"); <-- note the single quote then the double quote between the closing parenthesis.

Code: Select all

 
<?php require_once('../Connections/BrowardLimo.php'); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
 
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
$Paramid_WADAspecials = "-1";
if (isset($_GET['id'])) {
  $Paramid_WADAspecials = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_BrowardLimo, $BrowardLimo);
$query_WADAspecials = sprintf("SELECT id, specialName, createdBy, updatedBy, email, removeOn, date_added, comment FROM specials WHERE id = %s", GetSQLValueString($Paramid_WADAspecials, "int"));
$WADAspecials = mysql_query($query_WADAspecials, $BrowardLimo) or die(mysql_error());
$row_WADAspecials = mysql_fetch_assoc($WADAspecials);
$totalRows_WADAspecials = mysql_num_rows($WADAspecials);?>
<?php 
// WA Application Builder Update
if (isset($_POST["Update_x"])) // Trigger
{
  $WA_connection = $BrowardLimo;
  $WA_table = "specials";
  $WA_redirectURL = "specials_Detail.php?id=".((isset($_POST["WADAUpdateRecordID"]))?$_POST["WADAUpdateRecordID"]:"")  ."";
  $WA_keepQueryString = false;
  $WA_indexField = "id";
  $WA_fieldNamesStr = "specialName|updatedBy|email|removeOn|comment";
  $WA_fieldValuesStr = "".((isset($_POST["specialName"]))?$_POST["specialName"]:"")  ."" . "|" . "".((isset($_POST["updatedBy"]))?$_POST["updatedBy"]:"")  ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"")  ."" . "|" . "".((isset($_POST["removeOn"]))?$_POST["removeOn"]:"")  ."" . "|" . "".((isset($_POST["comment"]))?$_POST["comment"]:"")  ."";
  $WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|',none,''";
  $WA_comparisonStr = " LIKE | LIKE | LIKE | LIKE | LIKE ";
  $WA_fieldNames = explode("|", $WA_fieldNamesStr);
  $WA_fieldValues = explode("|", $WA_fieldValuesStr);
  $WA_columns = explode("|", $WA_columnTypesStr);
  
  $WA_where_fieldValuesStr = "".((isset($_POST["WADAUpdateRecordID"]))?$_POST["WADAUpdateRecordID"]:"")  ."";
  $WA_where_columnTypesStr = "none,none,NULL";
  $WA_where_comparisonStr = "=";
  $WA_where_fieldNames = explode("|", $WA_indexField);
  $WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
  $WA_where_columns = explode("|", $WA_where_columnTypesStr);
  $WA_where_comparisons = explode("|", $WA_where_comparisonStr);
  
  $WA_connectionDB = $database_BrowardLimo;
  mysql_select_db($WA_connectionDB, $WA_connection);
  if (!session_id()) session_start();
  $updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
  $WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues,  $WA_where_comparisons );
  $WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
  $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
  if ($WA_redirectURL != "")  {
    if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
      $WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
    }
    header("Location: ".$WA_redirectURL);
  }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/admin.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="description" content="Caracole" />
<title>admin</title>
<link href="favicon.ico" type="image/x-icon" rel="icon" />
    <link href="favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <link rel="stylesheet" type="text/css" href="../css/tripoli.simple.css" media="screen, projection, print" />
    <link rel="stylesheet" type="text/css" href="../css/layout.css" media="screen, projection, print" />
<script src="../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<script type="text/javascript">
        //<![CDATA[
        document.write('<link rel="stylesheet" type="text/css" href="../css/js/js.css" media="screen, projection, print" />');
        //]]>
    </script>
    <!--[if IE]>
        <link rel="stylesheet" type="text/css" href="../css/ie/ie.css" media="screen, projection, print" />
    <![endif]-->
    <!--[if lt IE 7]>
    <script src="js/DD_belatedPNG_0.0.7a-min.js" type="text/javascript"></script>
    <script>
        DD_belatedPNG.fix(' #header, h1, h1 a, .close, .field,.paginate .current, .icon, .required-icon, .search input');
    </script>
    <link rel="stylesheet" href="../css/ie/ie6.css" type="text/css" media="screen, projection"/>
    <![endif]-->
<link href="../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
</head>
<body>
 
<!-- Header -->
<!-- InstanceBeginEditable name="top" -->
<div id="header">
  <div class="container content">
    <h1><a href="../index.php" title="Back to home">Titanium</a></h1>
    <a href="http://www.pixelastic.com/" target="_blank" class="viewWebsite"><span>View website</span></a>
    <div class="loginInfos"> You're logged in as <strong>Admin</strong>. <a href="#" title="Edit your settings">Edit your settings</a>, or <a href="#" title="Log out">Log out</a></div>
  </div>
</div>
<!-- InstanceEndEditable -->
<!-- /Header -->
 
<!-- Global -->
<div id="page-content">
<!-- Sidebar -->
<!-- InstanceBeginEditable name="nav" -->
<ul id="MenuBar1" class="MenuBarHorizontal">
  <li><a href="specials_Results.php">Specials</a></li>
  <li><a href="email_Results.php">Email</a></li>
  <li><a href="#">test</a></li>
  <li><a href="#">Item 3.2</a></li>
  <li><a href="#">Item 3.3</a></li>
</ul>
<!-- InstanceEndEditable -->
<!-- /Sidebar -->
<!-- InstanceBeginEditable name="mainContent" -->
<div class="admincontainer">
 
 
<div class="WADAUpdateContainer">
  <?php if ($totalRows_WADAspecials > 0) { // Show if recordset not empty ?>
    <form action="specials_Update.php?id=<?php echo(rawurlencode($row_WADAspecials['id'])); ?>" method="post" name="WADAUpdateForm" id="WADAUpdateForm">
      <div class="WADAHeader">Update Record</div>
      <div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
      <table class="WADADataTable" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <th class="WADADataTableHeader">specialName:</th>
          <td class="WADADataTableCell"><input type="text" name="specialName" id="specialName" value="<?php echo(str_replace('"', '"', $row_WADAspecials['specialName'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">createdBy:</th>
          <td class="WADADataTableCell"><?php echo(str_replace('"', '"', $row_WADAspecials['createdBy'])); ?></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">updatedBy:</th>
          <td class="WADADataTableCell"><input type="text" name="updatedBy" id="updatedBy" value="<?php echo(str_replace('"', '"', $row_WADAspecials['updatedBy'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">email:</th>
          <td class="WADADataTableCell"><input type="text" name="email" id="email" value="<?php echo(str_replace('"', '"', $row_WADAspecials['email'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">removeOn:</th>
          <td class="WADADataTableCell"><input type="text" name="removeOn" id="removeOn" value="<?php echo(str_replace('"', '"', $row_WADAspecials['removeOn'])); ?>" size="32" /></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">date_added:</th>
          <td class="WADADataTableCell"><?php echo(str_replace('"', '"', $row_WADAspecials['date_added'])); ?></td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">&nbsp;</th>
          <td class="WADADataTableCell">&nbsp;</td>
        </tr>
        <tr>
          <th class="WADADataTableHeader">comment:</th>
          <td class="WADADataTableCell"><textarea name="comment" id="comment" cols="32"><?php echo(str_replace('"', '"', $row_WADAspecials['comment'])); ?></textarea></td>
        </tr>
      </table>
      <div class="WADAHorizLine"><img src="../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
      <div class="WADAButtonRow">
        <table class="WADADataNavButtons" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Update" id="Update" value="Update" alt="Update" src="../WA_DataAssist/images/Pacifica/Traditional_update.gif"  /></td>
            <td class="WADADataNavButtonCell" nowrap="nowrap"><a href="specials_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Pacifica/Traditional_cancel.gif" /></a></td>
          </tr>
        </table>
        <input name="WADAUpdateRecordID" type="hidden" id="WADAUpdateRecordID" value="<?php echo(rawurlencode($row_WADAspecials['id'])); ?>" />
      </div>
    </form>
  <?php } // Show if recordset not empty ?>
  <?php if ($totalRows_WADAspecials == 0) { // Show if recordset empty ?>
    <div class="WADANoResults">
      <div class="WADANoResultsMessage">No record found.</div>
    </div>
  <?php } // Show if recordset empty ?>
</div>
</div>
<!-- InstanceEndEditable --><!-- InstanceBeginEditable name="footer" -->
<div id="footer">footer</div>
<!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../SpryAssets/SpryMenuBarRightHover.gif"});
//-->
        </script>
</body>
<!-- InstanceEnd --></html>
<?php
mysql_free_result($WADAspecials);
?>
 
here is the code for that page where do I put it
ok i put that code on that page now it prints the normal default 0000-00-00 00:00:00 what do I do
also i changed the table
date_updated timestamp,
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mysql time stamp

Post by VladSun »

JakeJ wrote:mysql_query("UPDATE specials set date_updated = 'now()'"); <-- note the single quote then the double quote between the closing parenthesis.
???

Your query puts a string data ( "now()" ) into a timestamp field. It should be:[sql]UPDATE specials SET date_updated = now()[/sql]instead of[sql]UPDATE specials SET date_updated = 'now()'[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mysql time stamp

Post by VladSun »

bkchf123 wrote:now when they update that column i want the dateupdated to add time date automatically timestamp only works once
You may find triggers useful:

http://dev.mysql.com/doc/refman/5.0/en/triggers.html
There are 10 types of people in this world, those who understand binary and those who don't
bkchf123
Forum Newbie
Posts: 11
Joined: Mon Jan 25, 2010 3:01 pm

Re: mysql time stamp

Post by bkchf123 »

thank you i got it wo ill be back for more
Pefo
Forum Newbie
Posts: 9
Joined: Wed Dec 16, 2009 5:10 pm

Re: mysql time stamp

Post by Pefo »

Isn´t it possible to declare it in the table field as of MySQL manual:
In a CREATE TABLE statement, the first TIMESTAMP column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses, the column has the current timestamp for its default value, and is automatically updated.

...
Not what you were looking for perhaps?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mysql time stamp

Post by VladSun »

Pefo wrote:Isn´t it possible to declare it in the table field as of MySQL manual:
In a CREATE TABLE statement, the first TIMESTAMP column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses, the column has the current timestamp for its default value, and is automatically updated.

...
Not what you were looking for perhaps?
Nice one :) I thought ON UPDATE clause is for foreign keys only, but apparently it's not so:
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: mysql time stamp

Post by AbraCadaver »

Pefo wrote:Isn´t it possible to declare it in the table field as of MySQL manual:
In a CREATE TABLE statement, the first TIMESTAMP column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses, the column has the current timestamp for its default value, and is automatically updated.

...
Not what you were looking for perhaps?
Yes, so this would work if they reversed the order of the fields to make the `date_updated` the first one. Actually, if you just make it NOT NULL it will update on every record update without needing DEFAULT or ON UPDATE. Still, you need to set the `date_added` on the initial insert.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply