Numair
Numair

Reputation: 69

Codeigniter update records error

I am using codeigniter framework, and I keep getting this error when I submit my from to post to my database.

Controller

public function profilePic()
  { 
    if ($this->session->userdata('userLogin')) {
      $user_id = $this->session->userdata('user_id');
        $data = array();
         if (isset($_POST['add'])) {

            $pic = $this->input->post('profileFace');
            $front = $this->input->post('frontView');
            $left = $this->input->post('leftView');
            $right = $this->input->post('rightView');
            $back = $this->input->post('backView');

            $updtResult = $this->main_model->updateProfilePic($pic,$front,$left,$right,$back,$user_id);
                redirect("userProfile");
        } else {

          $data['userdata'] = $this->main_model->getUserData();
             $this->load->view("frontend/ajax-view", $data);
        }
    } else {
        redirect("/fitness");
    }
  }

Model

function updateProfilePic($pic,$front,$left,$right,$back,$user_id) {

  $check = $this->getUserData();
   if(count($check)!=0)
   {


      if($pic != "")
      {
       $data['image'] =  $pic;
      }
      if($front != "")
      {
        $data['front_view'] = $front;
      }
      if($left != "")
      {
        $data['left_view'] = $left;
      }
      if($right != "")
      {
        $data['right_view'] =$right;
      }
      if($back != "")
      {
        $data['back_view'] = $back;
      }

     // pr($data);

      $this->db->where('user_id',$user_id);
      $result = $this->db->update('fitness_users', $data);
    }

     return $result;
}

and the error i am getting is: enter image description here

Upvotes: 0

Views: 49

Answers (1)

Saty
Saty

Reputation: 22532

You can use set method to update your data and check your variable is set or not using isset()

if (isset($pic) && $pic != "") {
    $this->db->set("image", $pic);
}
if (isset($front) && $front != "") {
    $this->db->set("front_view", $front);
}
if (isset($left) && $left != "") {
    $this->db->set("left_view", $left);
}
if (isset($right) && $right != "") {
    $this->db->set("right_view", $right);
}
if (isset($back) && $back != "") {
    $this->db->set("back_view", $back);
}

// pr($data);

$this->db->where('user_id', $user_id);
$result = $this->db->update('fitness_users');

Upvotes: 1

Related Questions