在codeigniter中更新API的查询无效

问题描述 投票:1回答:1

我想编写一个API来更新sql中的数据。我正在使用CI。我是这个领域的新手。虽然我写过它不能在localhost本身工作。任何人都可以帮助我吗?我在这里附加我的控制器和模型。它显示错误,就像这个页面不起作用

    function editprofile($id,$data) {
                $this->db->where(array('user_id' => $id));
            $this->db->update('registrationdetails', $data);
                    if(!empty($id))
                    {
                        $result = true;
                    } else {
                        $result = false;
                    }
                    return $result;
                }
public function updateuser()
                {
                    $adminId = 1;
                    $AUTHENTIC_KEY = "4u0IOxa1YTwNo38QjArD9ysW6PgVnbX7vtlJ";
                    $user_id=2;
                    $firstname ="aiswarya";
                    $lastname ="mathew";
                    $email ="[email protected]";
                    $password ="aiswarya";
                    $confirmpassword ="aiswarya";
                    $contactnumber ="999999999";
                    $gender ="female";
                    $address ="canada"; 
                    $department ="cse";
                    $designation ="swe";
          $Admindetails = $this->common->CheckValidAdmin($adminId,$AUTHENTIC_KEY);
                    if($Admindetails != false)
                    {
                        $validAdmin = array('authentication_key' => $Admindetails->authentication_key,
                                                    'admin_id' => $Admindetails->id
                                                    );
        $data = array();
                        $data = array('firstname'=>$firstname,'lastname'=>$lastname,'email'=>$email,'password'=>$password,'confirmpassword'=>$confirmpassword,'contactnumber'=>$contactnumber,'gender'=>$gender,'address'=>$address,'department'=>$department,'designation'=>$designation);                                         
  $status = $this->user->editprofile($user_id,$data);
                                        if($status == true)
                                        {
                                            $response = array('status' => 200,
                                                              'message' => 'updated successfully',
                                                'admin_details' => $validAdmin
                                                              );

                                        } else {
                                            $response = array('status' => 404,
                                                              'message' => 'unable to add, please try again',
                                                              'admin_details' => $validAdmin);
                                        }

        } else { 
                            $response = array('status' => 404,
                                              'message' => 'Authentication Failed');
                    }
                    echo json_encode($response);

                }   
php android mysql api codeigniter
1个回答
3
投票
    function editprofile($data) {

         if(!empty($data['user_id']))
         {
            $this->db->where(array('user_id' => $data['user_id']));
            $this->db->update('registrationdetails', $data);
            $result = true;
         } else {
            $result = false;
         }
            return $result;
  }
  public function updateuser()
  {
      $data['adminId'] = 1;
      $data['AUTHENTIC_KEY'] = "4u0IOxa1YTwNo38QjArD9ysW6PgVnbX7vtlJ";
      $data['user_id']=2;
      $data['firstname'] ="aiswarya";
      $data['lastname'] ="mathew";
      $data['email'] ="[email protected]";
      $data['password'] ="aiswarya";
      $data['confirmpassword'] ="aiswarya";
      $data['contactnumber'] ="999999999";
      $data['gender'] ="female";
      $data['address'] ="canada";   
      $data['department'] ="cse";
      $data['designation'] ="swe";

      $Admindetails = $this->common->CheckValidAdmin($data['adminId'],$data['AUTHENTIC_KEY']);
      if($Admindetails != false)
      {
          $validAdmin = array('authentication_key' => $Admindetails->authentication_key,
                'admin_id' => $Admindetails->id);

            $status = $this->user->editprofile($data);
            if($status == true)
            {
                    $response = array('status' => 200,
                                    'message' => 'updated successfully',
                                    'admin_details' => $validAdmin
                                );

            } else {
                $response = array('status' => 404,
                                'message' => 'unable to add, please try again',
                                'admin_details' => $validAdmin);
            }

        } else { 
                $response = array('status' => 404,
                                'message' => 'Authentication Failed');
   }
   echo json_encode($response);

}

© www.soinside.com 2019 - 2024. All rights reserved.