I am trying to send values from AngularJS to PHP like below
loginService.js
'use strict';
app.factory('loginService',function($http)
{
return{
login:function(user){
var promise = $http.post('data/user.php',user); //send data to user.php
promise.then(function(msg){
if(msg.data=='succes') console.log('succes login');
else console.log('error login');
})
}
}
});
My PHP file is like below
user.php
<?php
$user=json_decode(file_get_contents('php://input'));
if($user->mail=='foysal@gmail.com' && $user->pass=='1234')
{
print 'succes';
}
else
{
print 'error';
}
?>
My output is like below
error login
loginCtrl.js
'use strict';
app.controller('loginCtrl',function($scope,loginService)
{
$scope.login=function()
{
loginService.login();
}
})
Could anyone say where is my mistake??
Thanks
I am getting a message like this "<br />↵<b>Notice</b>: Trying to get property of non-object in <b>D:\php\htdocs\login_angularjs\app\data\user.php</b> on line <b>14</b><br />↵"
"
How can I debug here ?? Like, is php file getting values ?? is php file sending values ??
UPDATE
I think I failed to gather the values from the HTML Form. I am giving HTML Form code here.Could you help me to figure out the issue ??
login.tpl.html
Welcome : {{user.mail}}
<div class="bs-example">
<form role="form" name="form1">
<div class="form-group">
<p>Welcome : {{user.mail}}</p>
<label for="exampleInputEmail">Mail</label>
<input type="text" placeholder="Enter name"
class="form-control" required ng-model="user.mail">
</div>
<div class="form-group">
<label for="exampleInputPassword">Password</label>
<input type="password" placeholder="Password"
id="exampleInputPassword" class="form-control" required
ng-model="user.pass">
</div>
<button class="btn btn-default" type="submit"
ng-disabled="form1.$invalid" ng-click="login(user)">Submit</button>
<p></p>
</form>
</div>