title: Inserting Data in mySql Database using AngularJs
body: <p>I am trying to insert some data in mysql database server using AngularJs with PHP/MySQL.But it's not working.Nothing is showing.Why it's not working ? My codes -</p>
  
  <p><strong>index.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"&gt;    &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body ng-app="myApp" ng-controller="empcontroller"&gt;
  
   &lt;form&gt;
  
  Employee Name:-&lt;input type="text" ng-model="uname" /&gt;
  Password:-&lt;input type="Password" ng-model="pass" /&gt;
  &lt;input type="button" value="Submit" ng-click="postData()" /&gt;
  
  &lt;/form&gt;
  
  &lt;script src="app.js"&gt;&lt;/script&gt;
  
   &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var app = angular.module('myApp', []);
  
  app.controller('empcontroller', function ($scope, $http) {
  $scope.postData = function (post) {
  var data = {
  uname:$scope.empcontroller.uname,
  pass:$scope.empcontroller.pass
  }
  $http.post("http://localhost/query.php", { 'uname':     $scope.empcontroller.uname, 'pass': $scope.empcontroller.pass })
  .success(function (data, status, headers, config) {
      console.log($scope.empcontroller.uname);
  });
  };   
  });
  </code></pre>
  
  <p><strong>query.php</strong></p>
  
  <pre><code>&lt;?php 
  header('Access-Control-Allow-Origin: *');
  header("Content-Type: application/json; charset=UTF-8");
  
  $mysql_host = "localhost";
  $mysql_database = "FirstDB";
  $mysql_user = "root";
  $mysql_password = "";
  // Create connection
  $conn = new mysqli($mysql_host, $mysql_user,    $mysql_password,$mysql_database);
  if ($conn-&gt;connect_error) {
  die("Connection failed: " . $conn-&gt;connect_error);
  } 
  $data = json_decode(file_get_contents("php://input"));
  $uname = mysql_real_escape_string($data-&gt;uname);
  $pass = mysql_real_escape_string($data-&gt;pass);
  
  $sql = "INSERT INTO Employee (Username,Password) VALUES ('$uname','$pass')";
  $result = $conn-&gt;query($sql);
  echo($uname);
  error_log($uname);
  $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>When I am trying to run the php file (query.php) in my localhost server - it gives me the following error -</p>
  
  <blockquote>
    <p><br />
    <b>Fatal error</b>:  Uncaught Error: Call to undefined function >mysql_real_escape_string() in I:\xampp\htdocs\query.php:15
    Stack trace:</p>
    
    <h1>0 {main}</h1>
    
    <p>thrown in <b>I:\xampp\htdocs\query.php</b> on line <b>15</b><br /></p>
  </blockquote>