Inserting future date into mysql from a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fridge
Forum Newbie
Posts: 3
Joined: Sun May 20, 2007 4:14 pm

Inserting future date into mysql from a form

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Fridge
Forum Newbie
Posts: 3
Joined: Sun May 20, 2007 4:14 pm

Post by Fridge »

The field 'eventdate' has a type 'date'... is this what you mean?

If not could you explain a little further please?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Oh.

You should echo $story['eventdate'] to see if it is even set.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Fridge
Forum Newbie
Posts: 3
Joined: Sun May 20, 2007 4:14 pm

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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);
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply