Php Codeigniter更新记录赢得';t保存在DB中
我在使用Codeigniter框架更新记录时遇到一些问题。我正在使用MVC模式和活动记录 该代码用于更新用户配置文件 没有错误,但不会保存到我的数据库。可能的解决方案是什么 模型(model\u users.php) 控制器(members.php) 视图(profile.php)Php Codeigniter更新记录赢得';t保存在DB中,php,mysql,database,codeigniter,Php,Mysql,Database,Codeigniter,我在使用Codeigniter框架更新记录时遇到一些问题。我正在使用MVC模式和活动记录 该代码用于更新用户配置文件 没有错误,但不会保存到我的数据库。可能的解决方案是什么 模型(model\u users.php) 控制器(members.php) 视图(profile.php) 可能有多种原因不起作用。然而,我在你的模型中看到了一些不完全正确的东西 除非用户表中只有一行(即使这样也不确定是否有效),否则应使用: $user_profile = $this->db->get_wh
可能有多种原因不起作用。然而,我在你的模型中看到了一些不完全正确的东西
除非用户表中只有一行(即使这样也不确定是否有效),否则应使用:
$user_profile = $this->db->get_where('ij_users',array('id'=>$this->session->usedata('id')));
/*supposing you have id as PK in the table, an active session for that id, and want to get the logged in profile user data */
通过查看您的模型代码,我没有看到任何主键ID,这是需要更新记录的地方。因此,将ID添加到模型文件中的$data数组中
$data = array(
'user_id/id' => $row->id //********* add id here *********
'user_fname' => $row->user_fname,
'user_lname' => $row->user_lname,
'user_pass' => $row->user_pass,
'user_company' => $row->user_company
);
从这里看来,您正在保存与以前相同的数据,那么您如何知道它没有保存?你收到你添加的任何消息了吗?另外,我不确定您是否可以使用update
的返回值来了解操作的结果:参见示例。@Salem Yes。我收到消息“成功保存!”,但当我查看数据库时,表仍然没有更新。
<div class="form-signin">
<?php echo form_open('members/validate'); ?>
<?php
echo '<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button><h5>All fields are required!</h5>';
echo validation_errors();
echo '</div>';
echo "<p><strong>Email address </strong></p>";
echo form_input('user_email', $this->input->post('user_email'), 'disabled');
echo "<p><strong>First name</strong></p>";
echo form_input('user_fname', $this->input->post('user_fname'));
echo "<p><strong>Last name</strong></p>";
echo form_input('user_lname', $this->input->post('user_lname'));
echo "<p><strong>Password </strong></p>";
echo form_password('user_pass');
echo "<p><strong>Re-type password </strong></p>";
echo form_password('user_re_pass');
echo "<p><strong>Company name</strong></p>";
echo form_input('user_company', $this->input->post('user_company'));
echo "<p>";
echo form_submit('save_submit', 'Save changes', 'class="btn btn-primary"');
?>
<a href="<?php echo base_url() . "members" ?>" class="btn btn-link btn-small">Cancel</a>
<?php
echo "</p>";
echo form_close();
?>
$user_profile = $this->db->get_where('ij_users',array('id'=>$this->session->usedata('id')));
/*supposing you have id as PK in the table, an active session for that id, and want to get the logged in profile user data */
$data = array(
'user_id/id' => $row->id //********* add id here *********
'user_fname' => $row->user_fname,
'user_lname' => $row->user_lname,
'user_pass' => $row->user_pass,
'user_company' => $row->user_company
);