Php 无法更新codeigniter中数据库中的字段
我正在尝试创建更新用户详细信息的函数。但是模型中的数据库事务失败。它只是弹出失败消息,没有给出任何数据库错误或任何东西 有没有一种方法可以查看db日志以便在控制器中的var_dump之类的模型中进行调试Php 无法更新codeigniter中数据库中的字段,php,codeigniter,mysqli,Php,Codeigniter,Mysqli,我正在尝试创建更新用户详细信息的函数。但是模型中的数据库事务失败。它只是弹出失败消息,没有给出任何数据库错误或任何东西 有没有一种方法可以查看db日志以便在控制器中的var_dump之类的模型中进行调试 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class edit_account extends CI_Controller { public function __construc
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class edit_account extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('form_validation');
$this->load->model('medit_account');
}
function index() {
}
function edit_dept_officer() {
$user_id = $this->session->userdata('user_id');
// retrieve data from db to edit from
$table = 'department_officer';
$user_data = $this->medit_account->get_current_user($table, $user_id);
var_dump($user_data);
$userid = $user_data[0]->OfficerID;
$data = array(
'officer_no' => $user_data[0]->officer_no,
'first_name' => $user_data[0]->first_name,
'last_name' => $user_data[0]->last_name,
'contact_no' => $user_data[0]->contact_no,
);
var_dump($userid);
//validation rules
// $this->form_validation->set_rules('officer_no', 'Officer ID ', 'trim|required');
$this->form_validation->set_rules('first_name', 'First Name ', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name ', 'trim|required');
$this->form_validation->set_rules('contact_no', 'Contact Number', 'trim|required|numeric');
var_dump($data);
if ($this->form_validation->run() == FALSE) {
//fail validation
// $this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
// var_dump('point');
} else {
// pass validation
$officer_no = $user_data[0]->officer_no;
$first_name = $this->input->post('first_name', TRUE);
$last_name = $this->input->post('last_name' , TRUE);
$contact_no = $this->input->post('contact_no', TRUE);
$array1 = array(
'officer_no' => $officer_no,
'first_name' => $first_name,
'last_name' => $last_name,
'contact_no' => $contact_no,
);
var_dump($array1);
echo 'braekpoint';
$tableid = 'OfficerID';
var_dump($userid);
var_dump($tableid);
var_dump($table);
if($this->medit_account->update_user( $userid, $array1)) {
// user creation ok
echo 'success';
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Department Officer is created !!!</div>');
// $this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
// redirect('edit_account');
} else {
// user creation failed
$this->session->set_flashdata('msg', '<div class="alert alert-warning text-center">There was a problem creating the Department Officer. Please try again.!!!</div>');
echo 'fail';
// send error to the view
$this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
}
}
}
控制器
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class edit_account extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('form_validation');
$this->load->model('medit_account');
}
function index() {
}
function edit_dept_officer() {
$user_id = $this->session->userdata('user_id');
// retrieve data from db to edit from
$table = 'department_officer';
$user_data = $this->medit_account->get_current_user($table, $user_id);
var_dump($user_data);
$userid = $user_data[0]->OfficerID;
$data = array(
'officer_no' => $user_data[0]->officer_no,
'first_name' => $user_data[0]->first_name,
'last_name' => $user_data[0]->last_name,
'contact_no' => $user_data[0]->contact_no,
);
var_dump($userid);
//validation rules
// $this->form_validation->set_rules('officer_no', 'Officer ID ', 'trim|required');
$this->form_validation->set_rules('first_name', 'First Name ', 'trim|required');
$this->form_validation->set_rules('last_name', 'Last Name ', 'trim|required');
$this->form_validation->set_rules('contact_no', 'Contact Number', 'trim|required|numeric');
var_dump($data);
if ($this->form_validation->run() == FALSE) {
//fail validation
// $this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
// var_dump('point');
} else {
// pass validation
$officer_no = $user_data[0]->officer_no;
$first_name = $this->input->post('first_name', TRUE);
$last_name = $this->input->post('last_name' , TRUE);
$contact_no = $this->input->post('contact_no', TRUE);
$array1 = array(
'officer_no' => $officer_no,
'first_name' => $first_name,
'last_name' => $last_name,
'contact_no' => $contact_no,
);
var_dump($array1);
echo 'braekpoint';
$tableid = 'OfficerID';
var_dump($userid);
var_dump($tableid);
var_dump($table);
if($this->medit_account->update_user( $userid, $array1)) {
// user creation ok
echo 'success';
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">Department Officer is created !!!</div>');
// $this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
// redirect('edit_account');
} else {
// user creation failed
$this->session->set_flashdata('msg', '<div class="alert alert-warning text-center">There was a problem creating the Department Officer. Please try again.!!!</div>');
echo 'fail';
// send error to the view
$this->load->view('header');
$this->load->view('edit_account_dept_view', $data);
$this->load->view('footer');
}
}
}
错误发生在哪里?哪一行?它不显示任何行,只是弹出失败消息,这是**if($this->medit\u account->update\u user($userid,$array1))**中if条件的另一部分@paskl您的方法“update_user”不返回任何值,这意味着在条件下调用永远不会工作。因此你总是在“其他”中。如果什么都没发生,你检查过数据库吗?你真的需要一个事务吗?如果是,那么您需要结束它——查看codeigniter手册中的代码行。还请记住,您可以使用if$this->db->impacted_rows()==“1”检查是否有更新,但如果您发送重复信息(如数据库中没有任何内容实际随更新而更改),则这将是错误的。即使删除了事务开始,也会发生同样的情况,检查了手册中的更新代码,我没有看到任何错误。数据库条目中没有任何更改@红花