Ionic And Mysql Login System

Hi Guys,

I am quite new to ionic and would like to learn by creating a login system, but it can’t log me in and bring me to next page, i am not sure whats wrong, hope you guys can give some solutions.

Here is my code for login.php
` <?php

$postdata = file_get_contents(“php://input”);
$loginData = json_decode($postdata);
$email = $loginData->email;
$password = $loginData->password;

$userData = array(‘userID’ => ‘’,
‘name’ => ‘’,
‘city’ => ‘’);

mysql_connect(“localhost”, “username”, “password”) or die(’{“userData”:’.json_encode($userData).’, “error”: {“code”: “003”, “message”: “Login error! Code: 003”}}’); // Connect to database server(localhost) with username and password.
mysql_select_db(“webcentu_onseral”) or die(’{“userData”:’.json_encode($userData).’, “error”: {“code”: “004”, “message”: “Login error! Code: 004”}}’);

if(!empty($email) && !empty($password)){

//echo($email.'  '.$password);

$email = mysql_escape_string($email);
$password = mysql_escape_string(md5($password));

$results = mysql_query("SELECT name, city FROM tbl_user WHERE name='".$username."' AND city='".$password."' LIMIT 1") or die('{"error":"Login error! Code: 003"}'); 
$match  = mysql_num_rows($results);

$res = mysql_fetch_assoc($results);

if($match > 0 ){		
	if ($res['active'] = 1) {
		// login success
		$userData['username'] = $res['name'];
		$userData['password'] = $res['city'];
		echo ('{"userData":'.json_encode($userData).',"error":{"code":"000","message":"Logged in as '.$userData['username']"}}');
	} else {				
		echo('{"userData":'.json_encode($userData).', "error":{"code":"001","message":"Your account has not been ativated. Please verify your account by clicking on the link in the activation email sent when you registered.\r\n If you did not receive an email, click on the Resend Activation Email link and make sure the email is not being blocked by your spam filter."}}');
	}
}else{
	// login failed
	echo ('{"userData":'.json_encode($userData).', "error": {"code": "002","message": "The email or password you entered is incorrect."}}');			
}

} else {
// something failed with submitting data, should never get here!
echo(’{“userData”:’.json_encode($userData).’, “error”: {“code”:“005”, “message”: “Login error! Code: 005”}}’);
}
?>`

app.js
`angular.module(‘ionicApp’, [‘ionic’,‘starter.controllers’])

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

.state('app', {
  url: "/app",
  abstract: true,
  templateUrl: "templates/menu.html",
  controller: 'AppCtrl'
})

.state('app.test', {
  url: '/test',
  views: {
    'menuContent': {
      templateUrl: 'templates/test.html'
    }
  }
})



.state('login', {
  url: "/login",
  templateUrl: "templates/login.html",
  controller: 'LoginCtrl'
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise(’/login’);
});
`

controller.js
angular.module(‘starter.controllers’, [])

.controller(‘AppCtrl’, function($scope) {
})

.controller(‘LoginCtrl’, function($scope, $LoginService) {

$scope.LogIn = function(user){
LoginService.loginUser(user)
.then(function (data) {
$state.go(‘app.test’);
}, function (data) {
$state.go(‘app.test’);
});
};
});`

services.js
`
.service(‘LoginService’, function ($q, $http) {
return {
loginUser: function (loginData) {
var deferred = $q.defer(),
promise = deferred.promise;

        $http({
            url: 'http://myurl/api/login.php',
            method: "POST",
            data: loginData,
            headers: {'Content-Type': 'application/json'}
        })
            .then(function (response) {
                if (response.data.error.code === "000") {
                    console.log("User login successful: " + JSON.stringify(response.data));
                    deferred.resolve(response.data);
                } else {
                    console.log("User login failed: " + JSON.stringify(response.data.error));
                    deferred.reject(response.data);
                }
            }, function (error) {
                console.log("Server Error on login: " + JSON.stringify(error));
                deferred.reject(error);
            });

        promise.success = function (fn) {
            promise.then(fn);
            return promise;
        };
        promise.error = function (fn) {
            promise.then(null, fn);
            return promise;
        };
        return promise;
    },
};

});
`

it does not redirect to another view both failed or success.

(I tried to format the code but i cant seem to do it right)