Jump to content

Text Field, Dates and Insert


Kemik

Recommended Posts

Hello,

 

The user types a date (dd-mm-YYYY) in to a text field, the date is checked against a regex and if it passes, is then inserted to a database.

 

For some reason inserting the date ($this->input->post('date')) directly in to the database gives the default for the field (0000-00-00).

 

I've tried doing date("d-m-Y", $this->input->post('date')) but get 1970-01-01 or something like that.

 

Do you have any advise for converting the text field input in to a format that can be inserted in to the database?

Link to comment
https://forums.phpfreaks.com/topic/69469-text-field-dates-and-insert/
Share on other sites

I'm using CodeIgnitor. I don't think it's affected though. I just used the $this->input->post('date') to get the textfield called date. When I echo $this->input->post('date') it comes out with the input as it should. It's just like $_POST['date'].

 

My data is being stored as DATE in a MySQL database.

 

Feel free to test it here. I've stopped it inserting to the database. It will just return the values.

 

Here's the insert code:

				$insert = array(
			   'date' => $this->input->post('datetime') ,
			   'details' => $this->input->post('event')
			);

			$this->db->insert('one_events', $insert);

 

The event text gets inserted but the date doesn't.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.