close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

DataAssist date field is not updating correctly

Thread began 8/05/2010 8:31 am by sandy170299 | Last modified 8/05/2010 3:25 pm by Jason Byrnes | 1786 views | 6 replies |

sandy170299

DataAssist date field is not updating correctly

I am using a MySQL database and the field type is set to DATE. Whenever I try to change the date, using DataAssist, it comes back to me as 0000-00-00. It's not updating correctly. The Update Option Data Type is being set to Date, within the DA wizard. I've never encountered this before and I'm not sure how to fix it...???

Sign in to reply to this post

Jason ByrnesWebAssist

when posting date data into a mySQL date column, it must be in the yyyy-mm-dd hh:mm:ss format.

any other format such as mm/dd/yyyy will cause this problem

you can use the php date function to reformat your date before it is entered into the db, send a copy of your page, And I will give your code change that needs to be made.

Sign in to reply to this post

sandy170299

Thanks, Jason. Here is the code. Another thing I'm using is a javascript date picker, which is formatting the date in another format. This is probably contributing, too?
******************************************************************
<?php require_once('../Connections/jimmy.php'); ?>
<?php require_once("../WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("../WA_iRite/WARichEditorPHP.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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_WADAevents = "-1";
if (isset($_GET['ID'])) {
$ParamID_WADAevents = (get_magic_quotes_gpc()) ? $_GET['ID'] : addslashes($_GET['ID']);
}
mysql_select_db($database_jimmy, $jimmy);
$query_WADAevents = sprintf("SELECT ID, eventName, eventDate, eventInfo FROM events WHERE ID = %s", GetSQLValueString($ParamID_WADAevents, "int"));
$WADAevents = mysql_query($query_WADAevents, $jimmy) or die(mysql_error());
$row_WADAevents = mysql_fetch_assoc($WADAevents);
$totalRows_WADAevents = mysql_num_rows($WADAevents);?>
<?php
// WA Application Builder Update
if (isset($_POST["Update_x"])) // Trigger
{
$WA_connection = $jimmy;
$WA_table = "events";
$WA_redirectURL = "events_Results.php";
$WA_keepQueryString = false;
$WA_indexField = "ID";
$WA_fieldNamesStr = "eventName|eventDate|eventInfo";
$WA_fieldValuesStr = "".((isset($_POST["eventName"]))?$_POST["eventName"]:"") ."" . "|" . "".((isset($_POST["eventDate"]))?$_POST["eventDate"]:"") ."" . "|" . "".((isset($_POST["eventInfo"]))?$_POST["eventInfo"]:"") ."";
$WA_columnTypesStr = "',none,''|',none,NULL|',none,''";
$WA_comparisonStr = "=|=|=";
$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_jimmy;
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);
}
}
?>
<?php include("adminHeader.php"); ?>
<link href="../WA_DataAssist/styles/Traditional_Granite Pine.css" rel="stylesheet" type="text/css" />
<link href="../WA_DataAssist/styles/Verdana.css" rel="stylesheet" type="text/css" />


<div class="WADAUpdateContainer">
<?php if ($totalRows_WADAevents > 0) { // Show if recordset not empty ?>
<form action="events_Update.php?ID=<?php echo(rawurlencode($row_WADAevents['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 width="600" border="0" cellpadding="0" cellspacing="0" class="WADADataTable">
<tr>
<th valign="top" class="WADADataTableHeader">Event Name/Location:</th>
<td valign="top" class="WADADataTableCell"><input type="text" name="eventName" id="eventName" value="<?php echo(str_replace('"', '&quot;', $row_WADAevents['eventName'])); ?>" size="32" /></td>
</tr>
<tr>
<th valign="top" class="WADADataTableHeader">Event Date:</th>
<td valign="top" class="WADADataTableCell"><input type="text" name="eventDate" id="eventDate" value="<?php echo(str_replace('"', '&quot;', $row_WADAevents['eventDate'])); ?>" size="32" />
<input name="pickDate" type="button" id="pickDate" onclick="KW_doCalendar('eventDate',0)" value="Pick Date" /></td>
</tr>
<tr>
<th valign="top" class="WADADataTableHeader">Event Info:</th>
<td valign="top" class="WADADataTableCell"><?php
// WebAssist iRite: Rich Text Editor for Dreamweaver
$WARichTextEditor_1 = CreateRichTextEditor ("eventInfo", "../WA_iRite/", "100%", "350px", "Basic", "../custom/events_Update_eventInfo1.js", "".$row_WADAevents['eventInfo'] ."");
?></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 border="0" align="right" cellpadding="0" cellspacing="0" class="WADADataNavButtons">
<tr>
<td class="WADADataNavButtonCell" nowrap="nowrap"><input type="image" name="Update" id="Update" value="Update" alt="Update" src="../WA_DataAssist/images/Granite Pine/Traditional_update.gif" /></td>
<td class="WADADataNavButtonCell" nowrap="nowrap"><a href="events_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Granite Pine/Traditional_cancel.gif" /></a></td>
</tr>
</table>
<input name="WADAUpdateRecordID" type="hidden" id="WADAUpdateRecordID" value="<?php echo(rawurlencode($row_WADAevents['ID'])); ?>" />
</div>
</form>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_WADAevents == 0) { // Show if recordset empty ?>
<div class="WADANoResults">
<div class="WADANoResultsMessage">No record found.</div>
</div>
<?php } // Show if recordset empty ?>
</div>
<?php include("adminFooter.php"); ?>
<?php
mysql_free_result($WADAevents);
?>

Sign in to reply to this post

sandy170299

Just out of curiousity, Jason, shouldn't this be a feature built in within DA, to fix the dates before inserting them into the database? Most people I know are not going to enter a date in a yyyy-mm-dd format. Just my thoughts... :)

Sign in to reply to this post

Jason ByrnesWebAssist

change:

php:
$WA_fieldValuesStr = "".((isset($_POST["eventName"]))?$_POST["eventName"]:"") ."" . "|" . "".((isset($_POST["eventDate"]))?$_POST["eventDate"]:"") ."" . "|" . "".((isset($_POST["eventInfo"]))?$_POST["eventInfo"]:"") ."";




to:

php:
$WA_fieldValuesStr = "".((isset($_POST["eventName"]))?$_POST["eventName"]:"") ."" . "|" . "".((isset($_POST["eventDate"]))?date("Y-m-d h:m:i", strtotime($_POST["eventDate"])):"") ."" . "|" . "".((isset($_POST["eventInfo"]))?$_POST["eventInfo"]:"") ."";





it can be argued both ways, if you had a text field where you where storing the date, you would not want the date format to automatically reformat it on insert, the issue only really occurs when you have a date field.

Sign in to reply to this post

sandy170299

Thank you - worked perfectly. Still would be nice if it would do it for you :)

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...