I am trying to insert an image and data to the database from a form validation method using php codeigniter . Here is my code,problem is will not insert the data and image to the database. Please help. Controller Page
public function gallery5()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('upload');
$this->load->model('Login_set');
$page_id =$this->uri->segment(3);
$data['e']=$this->Login_set->select1();
$this->load->view('App_stay/pages/hotel1_galery_event.php',$data);
}
public function gallery5_insert()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('Login_set');
$this->form_validation->set_rules('id','id');
$this->form_validation->set_rules('events','events','required');
$this->form_validation->set_rules('description','description','required');
if ($this->form_validation->run() == true)
{
$config['upload_path'] = 'application/views/App_stay/photo1/';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$field_name = "images";
if ( ! $this->upload->do_upload($field_name))
{
$error = array('error' => $this->upload->display_errors());
$page_id =$this->uri->segment(3);
$data['e']=$this->Login_set->select1_edit();
$this->load->view('App_stay/pages/hotel1_galery_event.php',$data, $error);
}
else
{
$image_path = $this->upload->data();
$this->Login_set->add_events();
$page_id =$this->uri->segment(3);
$data['e']=$this->Login_set->select1_edit();
$this->load->view('App_stay/pages/hotel1_galery_event.php',$data);
}
}
}
View Page
<form action="<?php echo base_url();?>index.php/Welcome/gallery5_insert" method="post" enctype="multipart/form-data">
<?php
foreach ($e->result_array() as $value){
?>
<div class="form-group has-info ">
<input type="hidden" name="id" value="<?php echo $value['event_id'];?>">
<?php }?>
<div class="form-group has-info col-lg-7">
<label class="control-label" for="inputSuccess">Event title</label>
<input type="text" class="form-control" name="events" id="events" >
</div>
<div class="form-group has-info col-lg-7 ">
<label>Event Description</label>
<textarea id="description" name="description" class="form-control " rows="3"></textarea><br><br>
</div>
<div class="form-group has-info col-lg-7">
<label>Event Related images</label>
<input type="file" name="images"><br>
</div>
<div class="form-group has-info col-lg-7">
<button type="submit" class="btn btn-primary">
<span>SUBMIT</span>
</button>
</div>
</div>
</form>
Model page
public function add_events()
{
$this->form_validation->set_message('events','events','required');
$this->form_validation->set_message('description','description','required');
$this->form_validation->set_message('images','images','required');
$this->load->database();
$this->load->helper('url');
$data = array(
'event_id'=>'',
'hotel_id'=>1,
'event_title'=>$this->input->post('events'),
'event_description'=>$this->input->post('description'),
'image_path' => $image_path[full_path]
);
$this->db->insert('event_hotel1', $data);
}