0

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

2
  • There ain't no $data defined in your model but you try to access it. Commented Sep 15, 2015 at 11:23
  • pr($data); is it showing any data? Commented Sep 15, 2015 at 11:24

1 Answer 1

1

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');
Sign up to request clarification or add additional context in comments.

8 Comments

now i got only this error You must use the "set" method to update an entry.
i got this error on live server but not getting this on local
please verify your column name and set method name
these all correct i am only getting this error on live server not on local it works fine on local
Where is your getUserData() function?? and post your form code??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.