更新我的记录时出错

error while updating my records

这是我的控制器:

        public function updatedata($id)
                {
                  //$id=$this->input->get('id');
                  $result['data']=$this->Form_model->displayrecordsById($id);

                      $this->form_validation->set_rules('fname', 'First name', 'required');
                      $this->form_validation->set_rules('lname', 'Last name', 'required');
                      $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
                      $this->form_validation->set_rules('email', 'Email', 'required|valid_email');

                      if ($this->form_validation->run() == FALSE)
                      {
                          $this->load->view('update_records',$result);
                      } 

                      else 
                      {
                          $config['upload_path']   = './uploads/';
                          $config['allowed_types'] = 'gif|jpg|png';
                          $this->load->library('upload', $config);

                              $fn=$this->input->post('fname');
                              $ln=$this->input->post('lname');
                              $un=$this->input->post('username');
                              $em=$this->input->post('email');
                              if($this->upload->do_upload('filename'))
                                   {
                                       $fi= $this->upload->data('file_name');
        //                               $file = ("uploads/".$result['data']->filename);
        //                                //delete the existing file if needed
        //                                if (file_exists($file)) {
        //                                    unlink($file);
        //                                }
                                   }
                              else
                                   {
                                      $fi= $result['data']->filename;
                                   }
                              $this->Form_model->updaterecords($fn,$ln,$un,$em,$fi,$id);
                              echo 'Successfully updated your record';
                              //exit();
                          } 
                      }

我正在尝试更新已经存储在数据库中的数据,它工作正常但我面临的问题是当我不想更新图像部分时,只说我想更新名字或者只是电子邮件,它也很好用,但后来当我在我的数据库中看到图像文件名被删除,因此图像也没有显示。

我面临的错误是:

A PHP Error was encountered Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/Form.php

Line Number: 146

Backtrace:

File: C:\xampp\htdocs\amit\application\controllers\Form.php Line: 146 Function: _error_handler

File: C:\xampp\htdocs\amit\index.php Line: 315 Function: require_once

请任何人帮助我,请我从昨天开始尝试解决此问题,但我无法这样做请任何人帮助我

希望对您有所帮助:

第一个:替换

$fi= $result['data']->filename;

有了这个

 $fi= $result['data'][0]->filename;

第二个:要替换现有图像,您应该像这样在配置中添加$config['overwrite']=TRUE;

$config['upload_path']   = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
/*........your other code .........*/

更多:https://www.codeigniter.com/user_guide/libraries/file_uploading.html#preferences