Kemik Posted September 15, 2007 Share Posted September 15, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/69469-text-field-dates-and-insert/ Share on other sites More sharing options...
Wuhtzu Posted September 15, 2007 Share Posted September 15, 2007 It seems like you are using some framework, please lets us know what framework it is. If you are not using any framework but a custom class or something please post some code Quote Link to comment https://forums.phpfreaks.com/topic/69469-text-field-dates-and-insert/#findComment-349050 Share on other sites More sharing options...
darkfreaks Posted September 15, 2007 Share Posted September 15, 2007 if you are storing it as text like days/month year in full you need "l F Y" will give you something like Saturday September 2007 Quote Link to comment https://forums.phpfreaks.com/topic/69469-text-field-dates-and-insert/#findComment-349054 Share on other sites More sharing options...
Kemik Posted September 15, 2007 Author Share Posted September 15, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69469-text-field-dates-and-insert/#findComment-349068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.