Reputation: 9
public function store(){
$id=$this->input->post('id');
$_POST['date_created']=date('Y-m-d');
if ($this->form_validation->run('registration') === TRUE)
{
$_POST['password']= md5($_POST['password']);
if(!empty($_FILES['profile_img']['name']))
{
echo 'file set ..1<br>';
if(!$this->upload->do_upload('profile_img'))
{
echo 'file uploading failed ..2';
$error = $this->upload->display_errors();
echo $error;
//here its not load the view.
$this->template->load('templates/template','emp/add-emp',$error);
}
else
{
$img = $this->upload->data();
$file_name ='images/'.$img['file_name'];
$data= elements(array('fname','lname','email','password','state','city','mobile','emp_role','profile_img','date_created'),$_POST,$file_name);
}
}
else
{
echo 'file not set..3';
$data= elements(array('fname','lname','email','password','state','city','mobile','emp_role','date_created'), $_POST);
}
if(empty($id)){
echo 'Add data ..4';
$this->emp_model->set($data);
// $this->crud->insert('info',$data);
echo '<script type="text/javascript">alert("Inserted Succesfully ");</script>';
redirect('employee/add','refresh');
}
else{
echo 'Update data ..5';
$this->emp_model->set($data,$id);
// update('info', $data, 'id', $id);
//$this->crud->update('info',$data,'id',$id);
echo '<script type="text/javascript">alert("Updated Succesfully ");</script>';
redirect('employee','refresh');
}
}
else
{
if(empty($id)){
echo 'add data validation falid ..';
$this->add();
}
else{
echo 'edit data validation falid ..';
$this->edit($id);
}
}
}
problem is that when file uploading failed means when file not image or excced file limit it comes into display errors function but i can't load my view ... so please tell me whats problem should there?
Upvotes: 0
Views: 66
Reputation: 2218
Using flashdata and redirect can redirect you while holding your error message for the next request:
if(! $this->upload->do_upload($file_name){
$error = $this->upload->display_errors();
$this->session->set_flashdata('error', '$error');
redirect('/somewhere', 'refresh');
}
Upvotes: 2