doutan4831 2017-03-11 07:55
浏览 45
已采纳

Codeigniter未定义变量[重复]

Undefined

Now I want to create update function and I had appeared problem with undefined variable. I am using same method in adding there this working fine. I am newbie in coding maybe there have simple answer but I cannot find.

Controller

$event_title = $this->input->post('title');
            $event_description = $this->input->post('description');
            $event_phone = $this->input->post('phone');
            $event_email = $this->input->post('email');
            $event_keywords = $this->input->post('keywords');
            $date_start = $this->input->post('date_start');
            $time_start = $this->input->post('time_start');
            $date_end = $this->input->post('date_end');
            $time_end = $this->input->post('time_end');

            $start = date_format(date_create( $date_start.' '.$time_start),"Y-m-d H:i:s");
            $end = date_format(date_create( $date_end.' '.$time_end),"Y-m-d H:i:s");




            if(!empty($_FILES['picture']['name']))
            {
                $data['picture'] = $this->validator->upload_image('./uploads/events/main','picture'); 
                $this->validator->resize_image($data['picture'],'./uploads/events/main','event_main_size');
            }

            $event_basic = [
                                'title'         => $event_title, 
                                'main_photo'    => $picture,
                                'description'   => $event_description,
                                'email'         => $event_email,
                                'phone'         => $event_phone,
                                'keywords'      => $event_keywords,
                                'start'         => $start,
                                'end'           => $end, 
                                'created_at'    => date('c')
                           ];

            $this->events_model->update_event_base($event_basic,$event_id);

Model

public function update_event_base($event_basic,$event_id){
    return  
    $this->db->where('event_id', $event_id)
             ->update('events', $event_basic);
}

Error

Severity: Notice

Message: Undefined variable: picture

</div>
  • 写回答

1条回答 默认 最新

  • douyan8027 2017-03-11 08:37
    关注

    Please check this.It may help you.

    $picture = $_FILES['picture']['name'];
         $event_basic = [
                                    'title'         => $event_title, 
                                    'main_photo'    => $picture,
                                    'description'   => $event_description,
                                    'email'         => $event_email,
                                    'phone'         => $event_phone,
                                    'keywords'      => $event_keywords,
                                    'start'         => $start,
                                    'end'           => $end, 
                                    'created_at'    => date('c')
                               ];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?