I am trying to insert the data to the database by php CodeIgniter and display the result in the same page during submit the button. Below is my code.The problem is i do not get any values from view page and i check the print_r which results an empty array. Please help. View Page
<div class="container col-lg-4">
<?php echo validation_errors(); ?>
<?php echo form_open('Welcome/gallery1'); ?>
<div class="form-group has-info">
<input type="hidden" name="id" value="">
<br>
<label class="control-label col-lg-6" for="inputSuccess">Offer title
</label>
<input type="text" class="form-control col-lg-6" name="offered" value="<?php if(isset($_POST['offered'])) echo $_POST['offered']; ?>" id="offered">
<label class="control-label col-lg-6" for="inputSuccess">Offer Description
</label>
<textarea id="description" name="description" value="<?php if(isset($_POST['description'])) echo $_POST['description']; ?>" class="form-control col-lg-6" rows="3" >
</textarea>
<br/>
<div>
<button type="submit" class="btn btn-primary col-lg-4">
<span>SUBMIT
</span>
</button>
</div>
</div>
<?php echo form_close(); ?>
</div>
Controller Page
public function gallery1()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->model('Login_set');
$form_data = $this->input->post();
$data1 = array('offer_id'=>$this->input->post('id'),
'hotel_id'=>1,
'offers_name'=>$this->input->post('offered'),
'offers_description'=>$this->input->post('description')
);
print_r($data1);
$this->Login_set->add_offer($data1);
$page_id =$this->uri->segment(3);
$data['h']=$this->Login_set->select();
$this->load->view('App_stay/pages/hotel1_galery.php',$data);
}
Model Page
<?php
class Login_set extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function add_offer($data1)
{
$this->load->database();
$this->load->helper('url');
if($this->db->insert('offer_hotel1',$data1))
return true;
else
return false;
}
}
?>