1
私はCodeigniterのデータベース更新レコードのコーディングを行っています。すべて正常に動作しますが、[保存]ボタンをクリックするとデータベースレコードは更新されません。古いデータベースレコードが表示されるたびに表示されます。私はデータベースレコードを更新したいが、これは何が問題なのか。私は行方不明を理解していない。必要なヘルプ。CodeIgniter - データベースレコードの更新
マイコントローラー:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Employee extends CI_Controller {
function __construct()
{
parent::__construct();
if($this->session->email == "")
{
redirect('login');
}
$this->load->model('EmployeeModel','EmployeeModel');
}
public function ViewEmployee()
{
$data['getEmployee'] = $this->EmployeeModel->getEmployee();
$this->load->view('view_employee',$data);
}
public function update($empID) {
$data['user'] = $this->EmployeeModel->get_by($empID);
$data['subview'] = 'Employee/edit_employee';
$this->load->view('edit_employee', $data);
}
public function edit() {
$empID = $this->input->post('empID');
//Check whether user upload picture
if(!empty($_FILES['picture']['name'])){
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['file_name'] = $_FILES['picture']['name'];
//Load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('picture')){
$uploadData = $this->upload->data();
$picture = $uploadData['file_name'];
}else{
$picture = '';
}
}else{
$picture = '';
}
$data = array(
'empFirstName' => $this->input->post('firstname'),
'empLastName' => $this->input->post('lastname'),
'empNO' => $this->input->post('employee_id'),
'designation' => $this->input->post('designation'),
);
$this->db->where('empID', $empID);
$this->db->update('tbl_employee', $data);
redirect('view_employee');
$this->update($empID);
}
}
マイモデル:
<?php
class EmployeeModel extends CI_Model
{
function __construct() {
parent::__construct();
}
public function EmployeeRegister($data)
{
$this->db->insert('tbl_employee',$data);
return true;
}
public function getEmployee()
{
$this->db->where('status',0);
$query = $this->db->get('tbl_employee');
return $query->result();
}
public function get_by($empID) {
$this->db->where('empID', $empID);
$user = $this->db->get('tbl_employee')->row();
return $user;
}
}
ビュー:
<?php
print_r($user)
?>
<?php echo form_open('Employee/edit'); ?>
<div class="row">
<div class="form-titles"> Personal Information</div>
<div class="col-lg-4 input_field_sections">
<h5>Employee Name <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="firstname" value="<?=$user->empFirstName?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Father's Name <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="lastname" value="<?=$user->empLastName?>"/>
</div>
</div>
<div class="row">
<div class="col-lg-4 input_field_sections">
<h5>NIC <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="cnic" value="<?=$user->cnic?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Date of Birth <span style="color: #cc0000">*</span></h5>
<input required="" type="text" class="form-control datepicker" name="birth_date" value="<?=$user->birth_date?>"/>
</div>
</div>
<div class="row">
<div class="col-lg-4 input_field_sections">
<h5>Mobile #<span style="color: #cc0000">*</span></h5>
<input required="" type="text" class="form-control" name="mobile" value="<?=$user->empMobile?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Phone #</h5>
<input type="text" class="form-control" name="phone" value="<?=$user->phone?>"/>
</div>
</div>
<div class="row">
<div class="col-lg-4 input_field_sections">
<h5>Email ID</h5>
<input type="email" class="form-control" name="email" value="<?=$user->empemail?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Current Photo</h5>
<input type="file" class="form-control" name="picture" value="<?=$user->picture?>"/>
<img src="<?php echo base_url().'uploads/'.$user->picture?>" style="width: 150px;height: auto;" />
</div>
</div>
<div class="row">
<div class="col-lg-8 input_field_sections">
<h5>Address/City <span style="color: #cc0000">*</span></h5>
<textarea required="" name="address" class="addres form-control" /><?=$user->empaddress?></textarea>
</div>
</div>
<div class="row">
<div class="form-titles" style="margin-top:40px;"> Job Information</div>
<div class="col-lg-4 input_field_sections">
<h5>Work Location <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="worklocation" value="<?=$user->worklocation?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Employee ID <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="employee_id" value="<?=$user->empNO?>"/>
</div>
</div>
<div class="row">
<div class="col-lg-4 input_field_sections">
<h5>Department <span style="color: #cc0000">*</span></h5>
<input required="" type="text" class="form-control" name="department" value="<?=$user->department?>"/>
</div>
<div class="col-lg-4 input_field_sections">
<h5>Designation <span style="color: #cc0000">*</span></h5>
<input required type="text" class="form-control" name="designation" value="<?=$user->designation?>"/>
</div>
</div>
<div class="col-lg-8 input_field_sections">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</form>
すべてのコードをアップロードしないでください。 –
'Model'' EmployeeRegister'関数でこれらの行を追加します' print_r($ data); exit; ' –
このコードは私には意味がありません。 'redirect(' user '); $ this-> update($ empID);' –