doukan6564 2019-08-07 10:17
浏览 61
已采纳

如果不更新图像codeigniter Php,则图像列为null

I am trying to update firstname,lastname,image in codeigniter,But whenever i update only first_name and last_name(not image) then image column become null in mysql,Where i am wrong Here is my code

Here is my model

$add_data['first_name'] = ($this->input->post('first_name') && !empty($this->input->post('first_name'))) ? $this->input->post('first_name') : NULL;     
$add_data['last_name'] = ($this->input->post('last_name') && !empty($this->input->post('last_name'))) ? $this->input->post('last_name') : NULL;     

$saveArr = [];
    if(!empty($this->input->post('first_name'))){
       $saveArr['first_name'] = $this->input->post('first_name');
    }
    if(!empty($this->input->post('last_name'))){
       $saveArr['last_name'] = $this->input->post('last_name');
    }   
if(!file_exists($_FILES['image']['tmp_name']) || !is_uploaded_file($_FILES['image']['tmp_name'])) 
    {
        $saveArr['image'] = $_FILES['image'];
    }
    else
    {
        $filename=time().uniqid(rand()).$_FILES['image']['name'];
        move_uploaded_file($_FILES["image"]["tmp_name"], "images/" . $filename);
        $saveArr['image']=$filename;
    }
$this->db->where('id',$add_data['user_id']);
$query=$this->db->update('users',  $saveArr);
  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在线教育培训平台,主要以点播视频和在线练习测试为主,除将视频做切片外,有其他哪种方式降低流量?(关键词-带宽速率)
      • ¥20 用c语音或c++实现银行叫号系统
      • ¥15 人工智能 规则正向演绎和推理
      • ¥20 基于STM32F401的电子密码锁设计
      • ¥15 famamacbeth回归中遇到only size-1 arrays can be converted to Python scalars,求解答
      • ¥15 单片机多个自锁按键的编程实践
      • ¥15 用python操作redis存储中文后,再取出的数据变成了乱码怎么办?
      • ¥15 C语言简单排序问题有偿求解
      • ¥20 请问图片的代码什么意思
      • ¥15 coq问题求带,有偿