We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

formatString for DateField won´t work!

Medium Priority
1,635 Views
Last Modified: 2013-12-12
Hello!

I want to format a DateField, which get his data and save the data from/to MYSQL database.
But everytime i get en error:

TypeError: Error #1034: Type Coercion failed: cannot convert "0000-00-00" to Date.
      at kunden/eventListener()[/Users/marioboro/Documents/Flex Builder 3/Kundenverwaltung/src/kunden.mxml:99]
      at kunden/__detailsButton_click()[/Users/marioboro/Documents/Flex Builder 3/Kundenverwaltung/src/kunden.mxml:147]

Please can somebody tell me, what i´m doing wrong?

Thank´s!
Mario
<mx:DateField id="dw_datum" formatString="YYYY-MM-DD"/>

Open in new window

Bild-3.jpg
Comment
Watch Question

Commented:
Your not sending a data back from mySQL.  Place a debug point in your event handler and inspect the resultEvent and see whats actually comming back from the backend.

Author

Commented:
Thank´s.
How i can do this?

Commented:
In flexbuilder in the first line of your result event handeler double click the numbers on the side.  This will put a small circle on the number.  Then run the project in debug mode.

Author

Commented:
In Debug Mode it highlight 2 lines in the code:

58:   _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

99:  _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

Commented:
OK so I'll assume now that your getting dates from mySQL and populating a datagrid?

Do they appear correctly in the datagrid?

Author

Commented:
Do you remember my example?

I load some data from mysql in a datagrid - that works perfect. When i highlight a row and click the open popup button, it load´s more data that belongs to the user. "dw_datum" is not shown in the datagrid, later then in the popup also dw_datum is displayed.

I have attach 2 txt-files. kunden.mxml is the main app, kundenDetails.mxml is the popup.
You´ll find the DateField at line 304 in kundenDetails.mxml

Thank´s!
kunden.txt
kundenDetails.txt

Commented:
OK add a test colum tot the datagrid using dw_datum as the datafield and take a look see if the data is coming back from mysql correctly.

Author

Commented:
Yes, data is coming back to the datagrid. It looks: 0000-00-00

Author

Commented:
And so looks the PHP
if (isset($_POST["emailaddress"]) && is_numeric($_POST["userid"])) {
	//mysql_query("INSERT INTO users (emailaddress,username) VALUES('".$_POST["emailaddress"]."','".$_POST["username"]."')");
	mysql_query("UPDATE users SET emailaddress='".$_POST["emailaddress"]."', username='".$_POST["username"]."', usernachname='".$_POST["usernachname"]."', anrede='".$_POST["anrede"]."', plz='".$_POST["plz"]."', ort='".$_POST["ort"]."', strasse='".$_POST["strasse"]."', tel_privat='".$_POST["tel_privat"]."', gebdatum='".$_POST["gebdatum"]."', beruf='".$_POST["beruf"]."', sonstiges='".$_POST["sonstiges"]."', dw_datum='".$_POST["dw_datum"]."', dw_bedienung='".$_POST["dw_bedienung"]."', dw_wickler='".$_POST["dw_wickler"]."', dw_anordnung='".$_POST["dw_anordnung"]."', dw_einwirkzeit='".$_POST["dw_einwirkzeit"]."', dw_nachbehandlung='".$_POST["dw_nachbehandlung"]."', dw_preis='".$_POST["dw_preis"]."', dw_anmerkungen='".$_POST["dw_anmerkungen"]."', fa_datum='".$_POST["fa_datum"]."', fa_bedienung='".$_POST["fa_bedienung"]."', fa_rezeptur='".$_POST["fa_rezeptur"]."', fa_einwirkzeit='".$_POST["fa_einwirkzeit"]."', fa_preis='".$_POST["fa_preis"]."', fa_anmerkungen='".$_POST["fa_anmerkungen"]."', image_url='".$_POST["image_url"]."' WHERE userid=".$_POST["userid"]);
}
 
 
$Query = "SELECT * from users";
$Result = mysql_query( $Query );
 
$Return = "<users>";
 
while ( $User = mysql_fetch_object( $Result ) )
{
$Return .= "<user><userid>".$User->userid."</userid><anrede>".$User->anrede."</anrede><username>".$User->username."</username><usernachname>".$User->usernachname."</usernachname><emailaddress>".$User->emailaddress."</emailaddress><plz>".$User->plz."</plz><ort>".$User->ort."</ort><strasse>".$User->strasse."</strasse><tel_privat>".$User->tel_privat."</tel_privat><gebdatum>".$User->gebdatum."</gebdatum><beruf>".$User->beruf."</beruf><sonstiges>".$User->sonstiges."</sonstiges><dw_datum>".$User->dw_datum."</dw_datum><dw_bedienung>".$User->dw_bedienung."</dw_bedienung><dw_wickler>".$User->dw_wickler."</dw_wickler><dw_anordnung>".$User->dw_anordnung."</dw_anordnung><dw_einwirkzeit>".$User->dw_einwirkzeit."</dw_einwirkzeit><dw_nachbehandlung>".$User->dw_nachbehandlung."</dw_nachbehandlung><dw_preis>".$User->dw_preis."</dw_preis><dw_anmerkungen>".$User->dw_anmerkungen."</dw_anmerkungen><fa_datum>".$User->fa_datum."</fa_datum><fa_bedienung>".$User->fa_bedienung."</fa_bedienung><fa_rezeptur>".$User->fa_rezeptur."</fa_rezeptur><fa_einwirkzeit>".$User->fa_einwirkzeit."</fa_einwirkzeit><fa_preis>".$User->fa_preis."</fa_preis><fa_anmerkungen>".$User->fa_anmerkungen."</fa_anmerkungen><image_url>".$User->image_url."</image_url></user>";
}

Open in new window

Commented:
Well that's not a valid date so there is your error :)

Now if you want a default date allow the coulm to have nulls set all the values to null then in flex do a check if dw_datum == null then _kundenDetails.dw_datum.selectedDate = null or new date() or what ever you want as default.

Author

Commented:
Thank´s, but please can you show me the solution in my code. And have i to change anything in the MYSQL db?

Commented:
Line 99 ish change:  _kundenDetails.dw_datum.selectedDate = dgUserRequest.selectedItem.dw_datum;

if( dgUserRequest.selectedItem.dw_datum == null){
     _kundenDetails.dw_datum.selectedDate = new Date();
}else{
  _kundenDetails.dw_datum.selectedDate = null;
}

Yes dont store invalid dates in mySQL.  While technically its valid its just better to store null if there is no date.

Author

Commented:
Thank´s.
I have modified the code. The error is away, but i when i define a date in the datefield, it will not be saved in the database.

And in the database i have store it to NULL, or not?

Commented:
Only the default date is null.

The date will save back to the database just fine.

Author

Commented:
And what have i now to change in the MYSQL DB?

Commented:
Allow NULL for the date field in the database.

As for the 0000-00-00 entries I'll presume this is just in testing so u can wipe the data so

update     tableName
set           columnName = null;

Will work.

1.jpg

Author

Commented:
OK, thank´s. Now when the popup is loaded, in the datefield the today´s date is shown. But when i change it and click my save button, it will not be saved in the database. Only 0000-00-00 instead of NULL.
Commented:
OK open a new question on how to save the date correctly and post the save Actionscript method and the php code.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thank´s!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.