# Cannot post myfirstionic/login\_service.php. My connection is working well.. Can anyone help me about this error? Thank you

**URL:** <https://forum.ionicframework.com/t/cannot-post-myfirstionic-login-service-php-my-connection-is-working-well-can-anyone-help-me-about-this-error-thank-you/58395>\
**Category:** ionic-v1\
**Created:** [July 23, 2016, 4:58pm UTC](https://forum.ionicframework.com/t/cannot-post-myfirstionic-login-service-php-my-connection-is-working-well-can-anyone-help-me-about-this-error-thank-you/58395 "2016-07-23T16:58:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pajimola](https://avatars.discourse-cdn.com/v4/letter/p/94ad74/32.png) [@Pajimola](https://forum.ionicframework.com/u/Pajimola)\
**Post date:** [July 23, 2016, 4:58pm UTC](https://forum.ionicframework.com/t/cannot-post-myfirstionic-login-service-php-my-connection-is-working-well-can-anyone-help-me-about-this-error-thank-you/58395/1 "2016-07-23T16:58:08Z")

</div>

This is my code in my controller.js  
.controller(‘loginCtrl’, function($scope,$http, $state) {  
//Variables  
$scope.loginInfo = {  
username: undefined,  
password: undefined  
}

```
var result = {
    test: undefined
}

result.test = {
    test: "test",
    test2: "test2",
    test3: "testers"
}

result.test = JSON.stringify(result.test);
//function
$scope.loginUser = function () {
     var data = {
        username: $scope.loginInfo.username,
        password: $scope.loginInfo.password
    }
    
    $http.post("myfirstionic/login_service.php", data).success(function(response){
        console.log(response);
        localStorage.setItem("token", JSON.stringify(response));
        $state.go("welcomePage", result);
    }).error(function(error){
        console.error(error);
    });

}

```

})

and for my login.php

\<?php header("Access-Control-Allow-Origin: \*"); require\_once('connection.php'); $data = json\_decode(file\_get\_contents("php://input")); $password = sha1($data-\>password); $username = $data-\>username; $userInfo = $db-\>query("SELECT email FROM users WHERE email='$username' AND password='$password'"); $userInfo = $userInfo-\>fetchAll(); $token; if (count($userInfo) == 1){ //This means that the user is logged in and let's givem a token :D :D :D $token = $username . " | " . uniqid() . uniqid() . uniqid(); $q = "UPDATE users SET token=:token WHERE email=:email AND password=:password"; $query = $db-\>prepare($q); $execute = $query-\>execute(array( ":token" =\> $token, ":email" =\> $username, ":password" =\> $password )); echo json\_encode($token); } else { echo "ERROR"; } ?\>

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [July 23, 2016, 9:46pm UTC](https://forum.ionicframework.com/t/cannot-post-myfirstionic-login-service-php-my-connection-is-working-well-can-anyone-help-me-about-this-error-thank-you/58395/2 "2016-07-23T21:46:13Z")

</div>

You shouldn’t be storing plaintext passwords in your database, and you also shouldn’t be reinventing the wheel by designing your own authentication token system. Use a standard like JWT.
