booxvid 0 Posted October 1, 2012 Share Posted October 1, 2012 public function create_blog(){ $this->load->view('header'); $this->form_validation->set_rules('blogtitle','Blog Title','required'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ $this->load->view('view_dashboard_addblog'); } else{ $title =$this->input->post('blogtitle'); $desc = $this->input->post('desc'); $data = array( 'blog_title'=>$title, 'description'=>$desc, 'blog_date'=>CURDATE(), 'blog_time'=>CURTIME()); $this->blog_model->insert_posts($data); echo ""; $this->load->view('view_blog'); } } My problem is, curdate() and curtime() function for mysql doesn't work at all, it says an undefined function, how to get the current date and time in Codeigniter and insert it into my mysql table Link to post Share on other sites
Mahngiel 16 Posted October 1, 2012 Share Posted October 1, 2012 You should combine both the date and the time into one datetime column. Then you just use date or CI's mdate: http://codeigniter.c...ate_helper.html ? Link to post Share on other sites
booxvid 0 Posted October 1, 2012 Author Share Posted October 1, 2012 Is there another way that I could separate the date and time because I have two columns in my mysql table the blog_date and blog_time Link to post Share on other sites
Mahngiel 16 Posted October 1, 2012 Share Posted October 1, 2012 you could, but there's no need for it. if you look at time or date you see that the value for such is calculated in one value. Therefore, it's needless for you to separate the code. Link to post Share on other sites
keevitaja 0 Posted October 9, 2012 Share Posted October 9, 2012 if you use active records, then adding the date should look something like this: $this->db->set('created', 'NOW()', FALSE)->insert('posts', $data); where table field created is mysql datetime. $data does not contain created at all. Link to post Share on other sites
jinijames 0 Posted October 20, 2012 Share Posted October 20, 2012 Inserting current time Codeigniter's active record. $data = array( 'name' => $name , 'email' => $email, 'time' => NOW() ); $this->db->insert('mytable', $data); Link to post Share on other sites
Recommended Posts
Archived
This topic is now archived and is closed to further replies.