Using Ionic framework I'm creating Mobile Hybrid App. when I'm trying to insert data into Database, blank data is getting inserted. I'm not able to figure out what is the silly mistake I'm doing. please help me out.
home.html
<ion-view view-title="Registration">
<ion-content class="padding">
<form>
<div class="list">
<label class="item item-input item-stacked-label">
<span class="input-label">First Name</span>
<input type="text" placeholder="John" name="firstName" ng-model="firstName">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Last Name</span>
<input type="text" placeholder="Doe" name="lastName" ng-model="lastName">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Email</span>
<input type="text" placeholder="john@suhr.com" name="email" ng-model="email">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Password</span>
<input type="password" placeholder="Password" name="password" ng-model="password">
</label>
<label class="item item-input item-stacked-label">
<span class="input-label">Confirm Password</span>
<input type="password" placeholder="Confirm Password" ng-model="confirmPassword">
</label>
<a href="#/login" ng-click="createAccount()" class="button button-outline button-block button-positive">
Create Account
</a>
</div>
</form>
</ion-content>
app.js
angular.module('starter', ['ionic', 'starter.controllers'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
}).config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
$stateProvider
.state('registration', {
url: '/registration',
templateUrl: 'templates/registration.html',
controller:'registrationCtrl'
}),
$urlRouterProvider.otherwise('/login');});
controller.js
angular.module('starter.controllers', []).controller('registrationCtrl', function($scope, $ionicNavBarDelegate, $http) {
$ionicNavBarDelegate.showBackButton(false);
$scope.createAccount = function() {
$http.post("http://proittechnology.com/dev/stylr/createAccount.php", {
'firstName': $scope.firstName,
'lastName': $scope.lastName,
'email': $scope.email,
'password': $scope.password
})
.success(function(data, status, headers, config) {
alert("Data inserted successfully");
});
}});
createAccount.php
$server = 'localhost';
$username ="xxx";
$passwd ='xxx';
$Dbase = 'xxx';
$db = mysqli_connect($server,$username,$passwd) or die("Could not connect database");
mysqli_select_db($db, $Dbase) or die("Could not select database");
$data = json_decode(file_get_contents("php://input"));
$firstName = mysql_real_escape_string($data->firstName);
$lastName = mysql_real_escape_string($data->lastName);
$email = mysql_real_escape_string($data->email);
$password = mysql_real_escape_string($data->password);
mysqli_query($db, "INSERT INTO users(`firstName`, `lastName`, `email`, `password`)VALUES('".$firstName."','".$lastName."','".$email."','".$password."')");