我试图通过php codeigniter向数据库插入值,并在提交期间在同一页面中显示结果。这是我的代码,问题是我不会收到任何错误消息,也不会将值插入数据库。请帮忙。 查看页面
<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>
控制器页面
public function gallery1()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('offered', 'required');
$this->form_validation->set_rules('description', 'required');
$page_id =$this->uri->segment(3);
$this->load->model('Login_set');
if ($this->form_validation->run() == FALSE)
{
$data['h']=$this->Login_set->select();
$this->load->view('App_stay/pages/hotel1_galery.php',$data);
}
else
{
$this->Login_set->save($data);
}
}
模特页面
public function add_offer()
{
$this->load->database();
$this->load->helper('url');
$hotel_id=1;
$id = $this->input->post('id');
$offered = $this->input->post('offered');
$description = $this->input->post('description');
$data = array('offers_name' => $this->input->post('offered'),
'offers_description' => $this->input->post('description')
);
return $this->db->insert('offer_hotel1',$data,array('hotel_id'=>$hotel_id));
}