Php 为什么在Codeigniter查询生成器中使用更新函数时Mysql数据库表列变为空
为什么某个特定列会更新为空值?如果我使用 $firstName=$this->input->post('first_name')//这是有价值的 如果我指定字符串值(硬编码),它工作得很好 $firstName=“First Name” 控制器中的配置文件更新功能Php 为什么在Codeigniter查询生成器中使用更新函数时Mysql数据库表列变为空,php,database,codeigniter,query-builder,Php,Database,Codeigniter,Query Builder,为什么某个特定列会更新为空值?如果我使用 $firstName=$this->input->post('first_name')//这是有价值的 如果我指定字符串值(硬编码),它工作得很好 $firstName=“First Name” 控制器中的配置文件更新功能 $user_id = $this->session->userdata('user_auth')->id; $firstName = $this->input->post('first_n
$user_id = $this->session->userdata('user_auth')->id;
$firstName = $this->input->post('first_name');
$lastName = $this->input->post('last_name');
$email = $this->input->post('email');
$data = array(
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
);
$this->User_model->update_profile($user_id, $data);
模型中的数据库更新
$this->db->where('id', $user_id);
$this->db->update('user', $data);
if ($this->db->affected_rows()>0){
return true;
}else{
return false;
}
表单视图
<form method="POST" enctype="multipart/form-data"
id="update_profile-form" class="update_profile-form"
action="<?php echo base_url(); ?>index.php/user/update_profile">
<div class="modal-body">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name</label>
<input style="padding: 5px;" type="text" class="form-input"
name="first_name"
id="first_name"
value=<?= $user->firstName ?>
/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="last_name">Last Name</label>
<input style="padding: 5px;" type="text" class="form-input"
name="last_name"
id="last_name"
value="<?= $user->lastName ?>"/>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="last_name">Email</label>
<input style="padding: 5px;" type="text" class="form-input"
name="email"
id="email" placeholder="Email"
value="<?= $user->email ?>"/>
<span
class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close-->
<!-- </button>-->
<input type="submit" value="Update" class="btn btn-primary"></input>
</div>
</form>
你能分享表单显示视图的代码吗?@javierlaroulet现在检查一下!是不是只有名字
没有更新?还是所有字段?@Javierlaroulet不,所有字段都从post方法中获取值。我知道已经晚了:这里的一个问题是,给出错误的数据库列是什么格式(理想情况下是Varchar)。你能确认一下格式吗?