title: AngularJS PHP MYSQL User Login
body: <p>I am working on a web application that requires the user to login in order to have access to the content. I am new to PHP, so I am trying to figure out if there is something wrong with my code when I try to retrieve the information from the database. </p>
  
  <pre><code>&lt;?php 
  
  include('./connection.php');
  $loginInfo = json_decode(file_get_contents('php://input'));
  $username = $loginInfo-&gt;username;
  $password = password_hash($loginInfo-&gt;password, PASSWORD_DEFAULT);
  
  $q = $db-&gt;prepare("SELECT * FROM userauth WHERE username=:username AND password=:password");
  $q-&gt;bindParam(':username', $username, PDO::PARAM_STR);
  $q-&gt;bindParam(':password', $password, PDO::PARAM_STR);
  $q-&gt;execute();
  
  $userRow=$q-&gt;fetch(PDO::FETCH_ASSOC);
  
  if($userRow == true){
      print 'success';
  }else{
      print 'error';
  }
  
  ?&gt;
  </code></pre>
  
  <p>Here is the Service for the Angular:</p>
  
  <pre><code>'use strict';
  
  app.factory('loginSrv', function($http,$location){
  return{
      login:function(loginInfo, scope){
          var $promise = $http.post('../app_back_end/app_endpoints/login.php', loginInfo);
          $promise.then(function(msg){
              if(msg.data == 'success'){
                  console.log('success login');
                  $location.path('/profile');
              }
              else {
                  console.log('error login');
                  scope.msgtxt = 'Want to try again? :)';
              }
          });
      }
  }
  });
  </code></pre>