我在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>
答案 0 :(得分:0)
使用此程序调试您的应用程序。
echo $ this-&gt; db-&gt; last_query();