【问题标题】:Update the database with codeigniter and display the updation in same page使用 codeigniter 更新数据库并在同一页面显示更新
【发布时间】:2015-12-16 09:40:27
【问题描述】:

我正在尝试通过 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);            
}

【问题讨论】:

    标签: php jquery ajax database codeigniter


    【解决方案1】:

    您正在将输入传递给模型,但它们正在传递给控制器​​函数..请更新

    控制器:

    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);
    }
    

    【讨论】:

      猜你喜欢
      • 2018-08-18
      • 2016-12-24
      • 2011-09-29
      • 1970-01-01
      • 2017-04-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多