codeigniter 更新我的记录时出错[重复]

qnyhuwrf  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(121)

This question already has answers here:

Reference - What does this error mean in PHP? (38 answers)
Closed 6 months ago.

  • This is my controller :*
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();
                          } 
                      }

im trying to update the data which is already stored in the database, its working fine but the issue im facing is that when i don want to update image section, say only if i want to update the first name or just email, its also working good but later when i see in my database the image file name is deleted and thus the image is also not getting displayed.
the error im facing is this :
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
please can any one help me out please im trying to fix this from yesterday but im unable to do so please can any one help me please

lrpiutwd

lrpiutwd1#

希望这对您有所帮助:
第一个:* 替换它 *

$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

相关问题