# How to post values from ionic to codeigniter rest api

**URL:** <https://forum.ionicframework.com/t/how-to-post-values-from-ionic-to-codeigniter-rest-api/144143>\
**Category:** Appflow\
**Created:** [October 10, 2018, 9:37am UTC](https://forum.ionicframework.com/t/how-to-post-values-from-ionic-to-codeigniter-rest-api/144143 "2018-10-10T09:37:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asha4640](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@asha4640](https://forum.ionicframework.com/u/asha4640)\
**Post date:** [October 10, 2018, 9:37am UTC](https://forum.ionicframework.com/t/how-to-post-values-from-ionic-to-codeigniter-rest-api/144143/1 "2018-10-10T09:37:27Z")

</div>

My ts file function is

save() {  
var link = ‘[http://localhost/apicode/index.php/Login/addUser](http://localhost/apicode/index.php/Login/addUser)’;  
var myData = JSON.stringify({name:this.registerForm.value.name,username: this.registerForm.value.username,password:this.registerForm.value.username});  
console.log(myData);  
this.http.post(link, myData)  
.subscribe(data =\> {  
this.data.response = data["\_body"];  
console.log(“success!”);  
this.navCtrl.navigateForward(’/login’);  
}, error =\> {  
console.log(“Oooops!”);  
});  
}

this codeigniter controller function

function addUser\_post(){

```
    $_POST = json_decode(file_get_contents('php://input'), true);
$postdata = $this->input->post();

     if(!$postData ){

            $this->response("Enter complete user information to save", 400);

     }else{

        $result = $this->login_model->add($postData);

        if($result === 0){

            $this->response("Userinformation coild not be saved. Try again.", 404);

        }else{

            $this->response("success", 200);  
       
        }

    }

}

```

 ![Screenshot%20(47)](https://global.discourse-cdn.com/ionicframework/original/3X/f/b/fbbd22f9445d650a0cbfe0279099e5cadfa2e1fb.png)

It shows the error when i call the save function

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:13pm UTC](https://forum.ionicframework.com/t/how-to-post-values-from-ionic-to-codeigniter-rest-api/144143/2 "2021-07-19T21:13:31Z")

</div>

Closed on July 19, 2021, 9:13pm UTC


