The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

How to validate login using Slim PHP

himeda.2000's Avatar


27 May, 2015 02:05 PM

I'm using AngularJS (Front end), Slim Framework (Back end), PHP and MySQL. I am trying to validate both user email and password with the database stored values but I am able to login with incorrect email and password. I can't see where is my problem. Please help me! Here is my code


<form novalidate name="SigninForm" id="add-new-form" method="post" action=""> <div class="form-group">
  <label for="first_name">Email:</label>
  <input class="form-control" type="text" ng-model="" required />

<div class="form-group"> <label for="address">Password:</label> <input class="form-control" type="text" ng-model="user.password" /> </div> <button class="btn btn-primary" ng-disabled="SigninForm .$invalid || isUnchanged(user)" id="login" ng-click="signin(user)">Login!</button></form>


angular.module('CrudApp', []).
  config(['$routeProvider', function($routeProvider) 
when('/', {templateUrl: 'assets/tpl/home.html', controller: HomeCtrl}).
 when('/login-user', {templateUrl: 'assets/tpl/login.html', controller: LoginCtrl}).
otherwise({redirectTo: '/'});
function HomeCtrl($scope, $http) 
    $scope.users = data;
function LoginCtrl($scope, $http, $location) {
  $scope.master = {};
  $scope.activePath = null;
  $scope.signin = function(user, AddNewForm) {
    $'api/login_user', user).success(function(){
      $scope.activePath = $location.path('/list-user');
      //alert('No access available.');
    $scope.reset = function() {
      $scope.user = angular.copy($scope.master);


require 'Slim/Slim.php';
$app = new Slim();
$app->post('/login_user', 'login');
function login()
{ $request = Slim::getInstance()->request(); $user = json_decode($request->getBody()); $email= $user->email; $password= $user->password; if(!empty($email)&&!empty($password)) { $sql="SELECT name, email FROM user WHERE email='$email' and password='$password'"; $db = getConnection(); try { $result=$db->query($sql); if (!$result) { // add this check. die('Invalid query: ' . mysql_error()); } $row["user"]= $result->fetchAll(PDO::FETCH_OBJ); $db=null; echo json_encode($row); } catch(PDOException $e) { error_log($e->getMessage(), 3, '/var/tmp/php.log'); echo '{"error":{"text":'. $e->getMessage() .'}}'; } } } function getConnection() { $dbhost=""; $dbuser="root"; $dbpass=""; $dbname="TQA"; $dbh = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $dbh; } ?>

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac