⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Date fields are not saving to database



Sanaa Alauddin Khan

Sanaa Alauddin Khan
  • profile picture
  • Member

Posted 03 August 2015 - 01:40 AM

Below is my controller. On adding I can see the datetime picker but it is not saving to database.

 

public function new_user_employment(){
           $this->load->library('session');
            $userid = $_SESSION['logged_in']["user_profile_id"];
            $this->load->library('grocery_CRUD');
            $this->load->database();
            $this->load->helper('url');
            $crud = new grocery_CRUD();
            echo "<h2>Registration Form - Employment Details</h2>";
            $crud->set_theme('datatables');
            $crud->set_subject('Employment Details');
            $crud->set_table('user_employment_details');
          $crud->set_relation('user_profile_id','user_profile','id');
           $crud->where('user_profile_id',$userid);
            $crud->required_fields('company_name','title','date_from','date_to','address1','address2','city','state','zip','country','work_email');
            $crud->set_relation('country','country','country_name');
            $crud->columns(array('company_name','title','date_from','date_to','address1','address2','city','state','zip','country','work_email'));
            $crud->add_fields(array('company_name','title','date_from','date_to','address1','address2','city','state','zip','country','work_email'));
            $crud->edit_fields(array('company_name','title','date_from','date_to','address1','address2','city','state','zip','country','work_email'));
            $crud->change_field_type('user_profile_id','invisible');
        $crud->change_field_type('added_on','invisible');
        $crud->change_field_type('added_by','invisible');
        $crud->change_field_type('updated_by','invisible');
            $crud->unset_export();
            $crud->unset_print();  
         $crud->callback_insert(array($this,'insert_employment'));
         $output = $crud->render();
            $this->_example_output($output);         
        }  

function insert_employment($post_array) {
       
            $user_employment_insert = array(
                "user_profile_id" => $_SESSION['logged_in']["user_profile_id"],
                "company_name" => $post_array["company_name"],
                "title" => $post_array["title"],
                "date_from" =>  $post_array["date_from"],
                "date_to" =>  $post_array["date_to"],
                "address1" => $post_array["address1"],
                "address2" => $post_array["address2"],
                "city" => $post_array["city"],
                "state" => $post_array["state"],
                "zip" => $post_array["zip"],
                "country" => $post_array["country"],
                "work_email" => $post_array["work_email"],
                 "added_on" => date('Y-m-d H:i:s'),         
                "added_by" => 'Web Registration',
        "updated_by" => 'Web Registration'
    );
  return $this->db->insert('user_employment_details',$user_employment_insert);
}    
// END - Store employment data in database -Author/Reviewer
 

 


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 03 August 2015 - 11:01 AM

Check format $post_array["date_from"] and $post_array["date_to"] - i think you need smth like date('Y-m-d H:i:s', strtotime($post_array["date_from"]));

 

Hi! Try to comment all fields and star with only one - date, and lets see whats happen.

p.s.$this->load->library('session'); - you dont need this code, just set session like autoload library in config/autoload
 


Sanaa Alauddin Khan

Sanaa Alauddin Khan
  • profile picture
  • Member

Posted 07 August 2015 - 04:13 AM

Thankyou Thankyou!! It worked!!!