我正在尝试通过php CodeIgniter将数据更新到数据库,并在更新期间在同一页面中显示结果。下面是我的代码。问题是它没有显示任何错误消息,并且没有更新数据库中的值,并且在更新后它没有在页面中显示任何值。请帮忙。 查看页面
<?php
echo form_open('Welcome/service1');
?>
<input type="hidden" name="servicer_id" value="<?php echo $value['service_id']?>">
<input type="hidden" name="servicer_name" value="<?php echo $value['servicer_name']?>">
<input type="hidden" name="servicer_email" value="<?php echo $value['servicer_email']?>">
<input type="hidden" name="servicer_checkin" value="<?php echo $value['servicer_checkin']?>">
<input type="hidden" name="servicer_checkout" value="<?php echo $value['servicer_checkout']?>">
<input type="hidden" name="servicer_requestdate" value="<?php echo $value['servicer_requestdate']?>">
<input type="hidden" name="servicer_detail" value="<?php echo $value['servicer_detail']?>">
<input type="hidden" name="servicer_contact" value="<?php echo $value['servicer_contact']?>">
<input type="hidden" name="servicer_priority" value="<?php echo $value['servicer_priority']?>">
<label class="radio-inline">
<input type="radio" <?php if($value['status']=="Complete") {?> checked="checked"<?php } ?> name="current_status" value="Complete">Complete
</label>
<label class="radio-inline">
<input type="radio" <?php if($value['status']=="Ongoing") {?> checked="checked"<?php } ?> name="current_status" value="Ongoing">Ongoing
</label>
<label class="radio-inline">
<input type="radio" <?php if($value['status']=="Rejected") {?> checked="checked"<?php } ?> name="current_status" value="Rejected">Rejected
</label>
<button type="submit" class="btn btn-default">
<span>Status</span>
</button>
<?php
echo form_close();
?>
Controller page
public function service1()
{
$this->load->helper('url');
$page_id =$this->uri->segment(3);
$this->load->model('Login_set');
$this->Login_set->add_status();
$data['s']=$this->Login_set->select2();
$this->load->view('App_stay/pages/hotel1_service.php',$data);
}
Model page
public function add_status()
{
this->load->database();
this->load->helper('url');
hotel_id=1;
servicer_name= $this->input->post('servicer_name');
servicer_email= $this->input->post('servicer_email');
servicer_checkin= $this->input->post('servicer_checkin');
servicer_checkout= $this->input->post('servicer_checkout');
servicer_requestdate= $this->input->post('servicer_requestdate');
servicer_detail= $this->input->post('servicer_detail');
servicer_contact= $this->input->post('servicer_contact');
servicer_priority= $this->input->post('servicer_priority');
status= $this->input->post('status');
service_id= $this->input->post('servicer_id');
data=array('hotel_id'=>$hotel_id,'servicer_name'=>$servicer_name,'servicer_email'=>$servicer_email,'servicer_checkin'=>$servicer_checkin,'servicer_checkout'=>$servicer_checkout,'servicer_requestdate'=>$servicer_requestdate,'servicer_detail'=>$servicer_detail,'servicer_contact'=>$servicer_contact,'servicer_priority'=>$servicer_priority,'status'=>$status);
this->db->where('service_id',$service_id);
this->db->update('service_hotel1',$data);
}
答案 0 :(得分:0)
您正在将输入传递给模型,但它们会传递给控制器功能..请更新
控制器:
public function service1()
{
/** you are posting the form to this function and not to the model.
* which is why all input->post must be here
*/
$servicer_name = $this->input->post('servicer_name');
$servicer_email = $this->input->post('servicer_email');
$servicer_checkin = $this->input->post('servicer_checkin');
$servicer_checkout = $this->input->post('servicer_checkout');
$servicer_requestdate= $this->input->post('servicer_requestdate');
$servicer_detail = $this->input->post('servicer_detail');
$servicer_contact = $this->input->post('servicer_contact');
$servicer_priority = $this->input->post('servicer_priority');
$status = $this->input->post('status');
$service_id = $this->input->post('servicer_id');
$this->load->helper('url');
$page_id = $this->uri->segment(3);
$this->load->model('Login_set');
$this->Login_set->add_status($servicer_name, $servicer_email, $servicer_checkin, $servicer_checkout, $servicer_requestdate, $servicer_detail, $servicer_contact, $servicer_priority, $status, $service_id);
$data['s'] = $this->Login_set->select2();
$this->load->view('App_stay/pages/hotel1_service',$data); //also view must be loaded without .php so $this->load->view('App_stay/pages/hotel1_service',$data);
}
型号:
public function add_status($servicer_name, $servicer_email, $servicer_checkin, $servicer_checkout, $servicer_requestdate, $servicer_detail, $servicer_contact, $servicer_priority, $status, $service_id)
{
$this->load->database();
$this->load->helper('url');
$hotel_id =1 ;
$data = array(
'hotel_id' => $hotel_id,
'servicer_name' => $servicer_name,
'servicer_email' => $servicer_email,
'servicer_checkin' => $servicer_checkin,
'servicer_checkout' => $servicer_checkout,
'servicer_requestdate' => $servicer_requestdate,
'servicer_detail' => $servicer_detail,
'servicer_contact' => $servicer_contact,
'servicer_priority' => $servicer_priority,
'status' => $status
);
$this->db->where('service_id',$service_id);
$this->db->update('service_hotel1',$data);
}