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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.