2017-01-07 100 views
0

我想我已經正確地寫這段代碼,但我得到一個關於缺少參數的問題,我選擇了文件圖像上傳,但我也得到這樣的錯誤。缺少參數在codeigniter中上傳圖像編輯數據

 
A PHP Error was encountered 

Severity: Warning 

Message: Missing argument 1 for Data_guru::edit() 

Filename: tim_monitoring/Data_guru.php 

Line Number: 90 

Backtrace: 

File: C:\xampp\htdocs\sdb\application\controllers\tim_monitoring\Data_guru.php 
Line: 90 
Function: _error_handler 

File: C:\xampp\htdocs\sdb\index.php 
Line: 315 
Function: require_once 

You did not select a file to upload. 

謝謝您的回答

我的控制器

public function edit($id) { 
$this->form_validation->set_rules('nama_guru','Nama Guru','required');  
$this->form_validation->set_rules('alamat','Alamat','required'); 

    if ($this->form_validation->run() === FALSE) { 
     $data = array ('title' => 'Edit Data Guru', 
         'detail' => $this->monitoring_model->detail_guru($id), 
         'isi' => 'monitoring/edit_guru_view' 
         ); 
    $this->load->view('monitoring/layout/wrapper',$data); 
    //Kalau Tidak Ada Error Data Guru DiUpdate 
    }else{ 
      $config['file_name']   = $this->input->post('nama_guru'); 
      $config['upload_path']   = './assets/image/guru/'; 
      $config['allowed_types']  = 'gif|jpg|png'; 
      $config['max_size']    = 3000; 
      $config['max_width']   = 3000; 
      $config['max_height']   = 3000; 

      $this->load->library('upload', $config); 

      if (! $this->upload->do_upload('foto_guru')) 
      { 
        echo $this->upload->display_errors(); 
      } 
      else 
      { 
        $gbr = $this->upload->data(); 
        $data = array(
          'foto_guru'  => $gbr['file_name'], 
          'id_guru'  => $this->input->post('id_guru'), 
          'nama_guru'  => $this->input->post('nama_guru'), 
          'jenis_kelamin' => $this->input->post('jen_kel'), 
          'alamat'  => $this->input->post('alamat'), 
          'tempat_lahir' => $this->input->post('tempat_lahir'), 
          'tgl_lahir'  => $this->input->post('tgl_lahir'), 
          'no_hp'   => $this->input->post('no_hp'), 
          'username'  => $this->input->post('username'), 
          'password'  => $this->input->post('password') 
        ); 

     $this->monitoring_model->edit_guru($data); 
     redirect(base_url().'tim_monitoring/data_guru'); 
    } 
} 
} 

我的模型

//Menampilkan Detail Guru Di Halaman Edit Guru 
public function detail_guru($id) { 
    $query = $this->db->get_where('t_guru', array('id_guru' => $id)); 
    return $query->row_array(); 
} 

//Update Data Guru Setelah Di Edit Di Halaman Edt 
public function edit_guru($data) { 
    $this->db->where('id_guru',$data['id_guru']); 
    return $this->db->update('t_guru',$data); 
} 

我查看

<form action="<?php echo base_url() ?>/tim_monitoring/data_guru/edit" class="form-horizontal" method="post"> 
     <div class="form-group"> 
     <label for="inputEmail3" class="col-sm-4 control-label">Nama Guru</label> 
     <div class="col-sm-6"> 
      <input type="text" name="nama_guru" class="form-control" placeholder="Nama Guru" value="<?php echo $detail['nama_guru'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Tempat Lahir</label> 
     <div class="col-sm-6"> 
      <input type="text" name="tempat_lahir" class="form-control" placeholder="Tempat Lahir" value="<?php echo $detail['tempat_lahir'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Tanggal Lahir</label> 
     <div class="col-sm-6"> 
      <input type="date" name="tgl_lahir" class="form-control" value="<?php echo $detail['tgl_lahir'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Alamat</label> 
     <div class="col-sm-6"> 
      <textarea name="alamat" class="form-control" rows="4" required><?php echo $detail['alamat'] ?></textarea> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">No Handphone</label> 
     <div class="col-sm-6"> 
      <input type="number" name="no_hp" class="form-control" placeholder="No Handphone" value="<?php echo $detail['no_hp'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label class="col-sm-4 control-label">Foto</label> 
     <div class="col-sm-6"> 
       <input type="file" name="foto_guru" id="exampleInputFile" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Username</label> 
     <div class="col-sm-6"> 
      <input type="text" name="username" class="form-control" placeholder="Username" value="<?php echo $detail['username'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Password</label> 
     <div class="col-sm-6"> 
      <input type="password" name="password" class="form-control" placeholder="Password" value="<?php echo $detail['password'] ?>" required> 
     </div> 
     </div> 
     <div class="form-group"> 
     <label for="inputPassword3" class="col-sm-4 control-label">Jenis Kelamin</label> 
     <div class="col-sm-6"> 
      <input type="radio" name="jen_kel" value="L"><label>&nbsp;Laki - Laki</label>&nbsp;&nbsp; 
      <input type="radio" name="jen_kel" value="P"><label>&nbsp;Perempuan</label> 
     </div> 
     </div> 

     <input type="hidden" name="id_guru" class="form-control" value="<?php echo $detail['id_guru'] ?>" required> 

     <div class="form-group"> 
     <div class="col-sm-4"> 
     </div> 
     <div class="col-sm-6"> 
      <button type="submit" class="btn btn-primary">Ubah Data</button> 
     </div> 
     </div> 
    </form> 
+1

你需要傳遞ID,形成行動在頁面加載。

/tim_monitoring/data_guru/edit/<?php echo $ id; //這個是你在頁面加載時必須從控制器傳入的?>」類=」 form-horizo​​ntal「method =」post「>'。 – Tpojka

+0

當我使用您的代碼時,缺少的參數不會再次顯示,但上載的圖像和輸入數據在數據庫中仍未更改。上傳圖片時出錯「您沒有選擇要上傳的文件」。謝謝你的回覆伴侶。上傳圖片中出現 – fiqur

回答

1

請參閱編輯()tim_monitoring的方法/ Data_guru.php多數民衆贊成必須需要一個參數傳遞可變$ ID的價值。

所以,你需要在窗體的行動

action="<?php echo base_url() ?>/tim_monitoring/data_guru/edit/<?php echo $detail['id_guru'] ?>"

添加以下URL上傳圖像格式必須要求屬性enctype="multipart/form-data

+0

我收到錯誤您嘗試上傳的文件類型和大小是不允許的。我上傳我的文件圖像並不比我的配置大,但爲什麼我得到這個錯誤。在插入數據我使用此代碼,可以,但不能編輯。謝謝你的回覆伴侶 – fiqur