close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Insert Date Problem

Thread began 3/10/2010 2:34 pm by fabianmcelhill370894 | Last modified 3/15/2010 6:53 pm by Jason Byrnes | 1534 views | 11 replies |

fabianmcelhill370894

Insert Date Problem

I have set up a simple mysql DB with 2 fields, Name and Date (I have used DATE in MySQL). I then have used Dataassist to create insert, detail and report pages. When I post a date on insert page using 30-04-2010 it just displays 0000-00-00 on the detail page. I am new to database, PHP and MySQL. Can anyone point me in the direction of what I am doing wrong?

Thanks for any help in advance?

Fabian

The code of insert page is:

<?php require_once('Connections/connDate.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php
// WA Application Builder Insert
if (isset($_POST["Insert_x"])) // Trigger
{
$WA_connection = $connDate;
$WA_table = "datetestTbl";
$WA_sessionName = "WADA_Insert_datetestTbl";
$WA_redirectURL = "datetestTbl_Detail.php";
$WA_keepQueryString = false;
$WA_indexField = "id";
$WA_fieldNamesStr = "id|Date|Name";
$WA_fieldValuesStr = "".((isset($_POST["id"]))?$_POST["id"]:"") ."" . "|" . "".((isset($_POST["Date"]))?$_POST["Date"]:"") ."" . "|" . "".((isset($_POST["Name"]))?$_POST["Name"]:"") ."";
$WA_columnTypesStr = "none,none,NULL|',none,NULL|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_connDate;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert datetestTbl</title>
<link href="WA_DataAssist/styles/Refined_Pacifica.css" rel="stylesheet" type="text/css" />
<link href="WA_DataAssist/styles/Arial.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="WADAInsertContainer">
<form action="datetestTbl_Insert.php" method="post" name="WADAInsertForm" id="WADAInsertForm">
<div class="WADAHeader">Insert 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">Date:</th>
<td class="WADADataTableCell"><input type="text" name="Date" id="Date" value="" size="32" /></td>
</tr>
<tr>
<th class="WADADataTableHeader">Name:</th>
<td class="WADADataTableCell"><input type="text" name="Name" id="Name" value="" size="32" /></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="Insert" id="Insert" value="Insert" alt="Insert" src="WA_DataAssist/images/Pacifica/Refined_insert.gif" /></td>
<td class="WADADataNavButtonCell" nowrap="nowrap"><a href="datetestTbl_Results.php" title="Cancel"><img border="0" name="Cancel" id="Cancel" alt="Cancel" src="WA_DataAssist/images/Pacifica/Refined_cancel.gif" /></a></td>
</tr>
</table>
<input name="WADAInsertRecordID" type="hidden" id="WADAInsertRecordID" value="" />
</div>
</form>
</div>
</body>
</html>

Sign in to reply to this post

Jason ByrnesWebAssist

the mySQL database will only accept the date in the format of yyyy-mm-dd.


the line of code that is setting up the insert is:

php:
$WA_fieldValuesStr = "".((isset($_POST["id"]))?$_POST["id"]:"") ."" . "|" . "".((isset($_POST["Date"]))?$_POST["Date"]:"") ."" . "|" . "".((isset($_POST["Name"]))?$_POST["Name"]:"") ."";




you can edit this to convert the date you enter to the proper format using the strtotime() and date() functions:

php:
$WA_fieldValuesStr = "".((isset($_POST["id"]))?$_POST["id"]:"") ."" . "|" . "".((isset($_POST["Date"]))?date("Y-m-d", strtotime($_POST["Date"])):"") ."" . "|" . "".((isset($_POST["Name"]))?$_POST["Name"]:"") ."";
Sign in to reply to this post

fabianmacs370894

Date Issue Solved

Jason,

That worked a treat on the insert page.

For the detail page I just had to add:

<?php echo date('d/m/Y',strtotime($row_WADAdatetestTbl['Date'])); ?>

All seems to be working perfect now.

Many thanks for the help.

Best Regards,

Fabian

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working.

Sign in to reply to this post

fabianmacs370894

Update page not working correctly

Jason, thanks for sending through that info. I have now got most of it up and running except for the update page. When I insert a new record, all is fine, when I go to the update page the correct date format is showing, problem is when I change the date and submit it again I just get an empty page and it doesn't post the new changes to the DB. Any solutions?

Thanks,

Fabian

Attached Files
dataassist.zip
Sign in to reply to this post

Jason ByrnesWebAssist

if the page is blank, it means a php error is occurring but error reporting is turned off, add the following code at line 1 to turn error reporting on:

php:
<?php

error_reporting
(E_ALL);
ini_set('display_errors','on');
?>
Sign in to reply to this post

fabianmacs370894

Error on Update page

Fatal error: Call to undefined function  strtotime() in /Applications/MAMP/htdocs/events/datetestTbl_Update.php on line 59

LINE 59
$WA_fieldValuesStr = "".((isset($_POST["event_date"]))?date("d-m-Y",*strtotime($WADAdatetestTbl['event_date'])):"") ."" . "|" . "".((isset($_POST["event_name"]))?$_POST["event_name"]:"") ."";

It still shows the date format on the update page as yyyy-mm-dd, it needs to be dd-mm-yyyy.

I have attached the update page file.

Thanks.

Attached Files
datetestTbl_Update.php.zip
Sign in to reply to this post

John LangerBeta Tester

You have an * in front of strtotime (*strtotime) I don't think that's supposed to be there.

Sign in to reply to this post

fabianmacs370894

Update page error

John,

Thanks for your replay. Tried removing the * and it still shows error

$WA_fieldValuesStr = "".((isset($_POST["event_date"]))?date("d-m-y",*strtotime($WADAdatetestTbl['event_date'])):"") ."" . "|" . "".((isset($_POST["event_name"]))?$_POST["event_name"]:"") ."";

The line works fine on the insert page. Do you think it should work the same for update page?

Thanks, Fabian

Sign in to reply to this post

John LangerBeta Tester

Fabian,

I'm close but not close enough I'm afraid. And I've now run out of time as I'm going out. However this is where I'm at.

Change line 105 to

php:
<td class="WADADataTableCell"><input type="text" name="date_name" id="date_name" value="<?php echo date('d/m/Y',strtotime($row_WADAdatetestTbl['event_date'])); ?>" size="32" /></td>

That will display the existing date in the format you like.

The thing that I'm not getting is how to convert that back so the MySql will accept it. The example that Jason gave does not seem to work when Updating a record.

How ever you do have an error in Line 55. You have the date set to d-m-Y and it should be Y-m-d which is the MySql way of writing it.

This is the line in full but it still updates with 000-00-00 so I'm stumped now and have no time to continue to play with it. Perhaps someone else will come to our rescue.

php:
$WA_fieldValuesStr = "".((isset($_POST["event_date"]))?date("Y-m-d", strtotime($_POST["event_date"])):"") ."" . "|" . "".((isset($_POST["event_name"]))?$_POST["event_name"]:"") ."";



Incidentally you had the wrong field name in line 105. I think it was date_name instead of event_date so that was causing an error as well.

Sign in to reply to this post
loading

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...