mysql - Ionic : unable to send form data to php on MAMP server -
i started developing app's using ionic. more familiar mysql backend solutions, want : extract credentials form , send them php file on mamp server. file check wether account exists , respond.
here's form:
<form name="loginform" novalidate> <!-- ng-submit="login(loginform)" --> <div class="section-big"> <div id="logo_container"> <img src="img/logo.png" id="logo"> </div> <div id="login_container"> <input class="login_item" name="email" type="email" ng-model="userdata.email" placeholder="email" ng-minlength="5" required> <input class="login_item" name="password" type="password" ng-model="userdata.password" placeholder="password" ng-minlength="5" required> </div> </div> <span> {{responsemessage}} </span> <div class="section-small"> <button type="button" class="button button-full button-outline button-light login-inactive" ng-show="loginform.$invalid">login</button> </div> </form> the function in ionic controller :
$scope.login = function(userdata) { $scope.responsemessage = "in treatement"; console.log($scope.userdata.email) var request = $http({ method: 'post', url: 'http://localhost:8888/login.php', crossdomain: true, headers: {'content-type' : 'application/x-www-form-urlencoded'}, data: { email: $scope.userdata.email, password: $scope.userdata.password }, }); console.log("passed"); request.success(function(data) { if(data == "1"){ $scope.responsemessage = "login successful"; } else { $scope.responsemessage = "wrong credentialsemai"; } }); console.log("end reached"); } the login.php file (based on findings on stackskills):
<?php header("content-type: application/json; charset=utf-8"); header('access-control-allow-origin: *'); header('access-control-allow-methods: get, post'); $postdata = file_get_contents("php://input"); $request = json_decode($postdata); $email = $request->email; $password = $request->password; include_once 'dbconnect.php'; $request = "select * user email ='$email' , password = '$password'"; $result = $conn->query($request); if($result){ echo "1"; } else { echo "0"; } ?> the state of things : currently, login function triggered. as{{ responsemessage }} doesn't change, assume information isn't sent / doesn't make `login.php.
does have idea either fix or alternative still using ionic php mysql ?
edit:
data being retrieved, still unable send due following error: syntaxerror: unexpected token n
thanks !
this error because in php first line header("content-type: application/json; charset=utf-8");
that means try encode response in json returning string 1 or 0
try following in php.
if($result){ echo json_encode(array("status"=>1)); } else { echo json_encode(array("status"=>0)); }
Comments
Post a Comment