Page 1 of 1

Inserting future date into mysql from a form

Posted: Sun May 20, 2007 5:56 pm
by Fridge
I have a problem with a date insertion. I am quite new to PHP and mySQL and this is the first problem I have come up against.

I wish for a user to insert events into a form... all the other requests for info will write to their respected areas and have no problem being pulled back out, except the event date...

The code I am using inside the form is this:

<input size="40" name="eventdate"
value="<?php echo date($story['eventdate']);?>">

but the result is always 0000-00-00 as the date entered will not write to the database...

What I need is for the date to be entered in this format so that I can use the date to return a search query so that all entries will display date ascending (or descending).

The Sql $eventdate is set to date, and value is 0000-00-00... the right date can be entered through the phpmyadmin built in calender, but not through the form.

Any help will be received with great thanks,

Fridge

Posted: Sun May 20, 2007 6:03 pm
by s.dot
is $story['eventdate'] a timestamp?

If so

Code: Select all

<?php echo date("Y-m-d", $story['eventdate']);?>
"Y-m-d" could be replaced with the date formatting of your choice.

Posted: Sun May 20, 2007 6:12 pm
by Fridge
The field 'eventdate' has a type 'date'... is this what you mean?

If not could you explain a little further please?

Posted: Sun May 20, 2007 6:20 pm
by s.dot
Oh.

You should echo $story['eventdate'] to see if it is even set.

Posted: Sun May 20, 2007 6:39 pm
by Fridge
Nice one, Mate...

Your test suggestion revealed a floor in my event submit page... I had been messing and removed the reference to eventdate completly...

I have to say it's easy for a relative PHP new boy to get lost in code.

Thank you... it now works

Posted: Sun May 20, 2007 7:27 pm
by s.dot
To catch these type of errors in the future, you should change your .ini file to display all errors (E_ALL) if you have access to it, or you can place the following at the top of the page:

Code: Select all

ini_set('display_errors', 'On');
error_reporting(E_ALL);