Could not update data in REST API |
Note : I have not used any libraries and my code is.,
Controller file : Api.php public function customer_update_api(){ $path = $_FILES['customer_image']['name']; $path_tmp = $_FILES['customer_image']['tmp_name']; $final_name = $path; move_uploaded_file( $path_tmp, './public/images/customers/'.$final_name ); $id = $_POST['customer_id']; $customer_name = $_POST['customer_name']; $customer_image = $final_name; $customer_address = $_POST['customer_address']; $customer_city = $_POST['customer_city']; $customer_state = $_POST['customer_state']; $customer_pincode = $_POST['customer_pincode']; $customer_phone_no = $_POST['customer_phone_no']; $customer_email = $_POST['customer_email']; $customer_password = md5($_POST['customer_password']); $status = $_POST['status']; if(!$customer_name || !$customer_image || !$customer_address || !$customer_city || !$customer_state || !$customer_pincode || $customer_phone_no || !$customer_email || !$customer_password || !$status){ //$this->response("Enter complete Product information to save", 400); echo json_encode ( array( "Status"=>'Failed', "Error"=>'All Fields are Mandatory', )); }else{ $result = $this->Model_api->update_customer($id,array("customer_name"=>$customer_name, "customer_image"=>$customer_image, "customer_address"=>$customer_address, "customer_city"=>$customer_city, "customer_state"=>$customer_state, "customer_pincode"=>$customer_pincode, "customer_phone_no"=>$customer_phone_no, "customer_email"=>$customer_email, "customer_password"=>$customer_password, "status"=>$status)); if($result === 0){ //$this->response("Book information could not be saved. Try again.", 404); echo json_encode ( array( "Status"=>'Failed', //"Seller Details"=>$query->result(), //$this->response->statusCode(200), )); //$this->response->statusCode(200); }else{ //$this->response("success", 200); echo json_encode ( array( "Status"=>'Success', //"Seller Details"=>$result->result(), )); } } } ------------------------------------------------------------------------------------------------------------ Model File : Model_api.php //API call - update a customer public function update_customer($id, $data){ $this->db->where('customer_id', $id); if($this->db->update('customers_info', $data)){ return true; }else{ return false; } } ------------------------------------------------------------------------------------------------------------ categories_info Table @ https://ibb.co/QDpykdD products_info Table @ https://ibb.co/5cc3ZSM |
Welcome Guest, Not a member yet? Register Sign In |