2015-12-16 101 views
1

我想通過php CodeIgniter更新數據到數據庫,並在更新過程中在同一頁面顯示結果。下面是我的代碼。問題是它沒有顯示任何錯誤消息,並沒有更新數據庫中的值,並且在更新後不在頁面中顯示任何值。請幫忙。 查看頁面用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

你傳入輸入到模型,但之後就被傳遞給控制器​​功能..請更新

控制器:

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); 
} 
相關問題