Forums

Date Insert Problem

decbuck 28 Nov, 2008
Hi

I used the cf to insert form into a mysql db. It works fine apart from one thing. I have a date field in my form that selects the date in format DD/MM/YYYY but the default value of the mysql field is 0000-00-00. The date never insterts into the date column instead entering the default value. I have the columns set as type date.

Do I need to do something to my form, db table to get the date to enter correctly?

Thanks
GreyHead 28 Nov, 2008
Hi decbuck,

There's always a problem with date formats. You have a choice of saving as Date, Timestamp, or Text field and you need to handle the necessary conversion in the OnSubmit After box.

Because of the ambiguity in dd/mm & mm/dd formats you'll probably need to explode your dd/mm/yyyy date into an array, then use date() to convert the array elements into the MySQL format. (I think that using date will validate the date as well.)

Bob
decbuck 28 Nov, 2008
Have you an example of this code?
GreyHead 28 Nov, 2008
Hi decbuck,

Not without writing it from scratch . . . but Google is your friend - try this thread or Google on "save dd/mm/yyyy as mysql date php" for more.

Bob
decbuck 28 Nov, 2008
Hi

Still having a few problems with this. I am trying to access my form variables in the "On Submit code - after sending email: (PHP code with tags) " code and I cannot. How do I know my variable names. Are these from the form code as in the "id"


I undertand the conversion stuff but just cannot access the variables.


Also, when exactely is it put into the db. Is it after this last "after sending e-mail" is executed?

Many thanks.
decbuck 28 Nov, 2008
Sorry got it.

echo $_POST['[i]varname[/i]'];
This topic is locked and no more replies can be posted.