我想我已经正确地编写了这段代码,但是我遇到了缺少参数的问题,我选择了要上传的文件图像,但我得到的错误就是这样。
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> Laki - Laki</label>
<input type="radio" name="jen_kel" value="P"><label> 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>
答案 0 :(得分:1)
请参阅编辑() tim_monitoring / Data_guru.php 的方法,必须要求将一个参数作为变量 $ id的值传递强>
因此,您需要在表单的操作中添加以下网址
<强> action="<?php echo base_url() ?>/tim_monitoring/data_guru/edit/<?php echo $detail['id_guru'] ?>"
强>
对于上传图片表单,必须要求属性 enctype="multipart/form-data
&#34;