title: How do I connect to mysql from Ionic mobile apps?
body: <p>I try to connect my ionic app to mysql using php but it doesn't work .
  xampp use port 8180 and ionic use port 8100 </p>
  
  <pre><code>.controller('AddController',['$scope','$http',function($scope,$http){
    $scope.enregistrer=function(){
      $scope.responseMessage="pfffff";
      $http.post("http://localhost:8180/add.php",{'nom':$scope.nom,
                            'prenom':$scope.prenom,
                            'email':$scope.email,
                            'adresse':$scope.adresse,
                            'sexe':$scope.sexe,
                            'active':$scope.active}).success(function(data,status,headers,config) {  
                                          $scope.responseMessage = "Successfully Created Account";;
                                        });
   }
  }]);
  </code></pre>
  
  <p>add.php :</p>
  
  <blockquote>
    <p>if (isset($_SERVER['HTTP_ORIGIN'])) {
            header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
            header('Access-Control-Allow-Credentials: true');
            header('Access-Control-Max-Age: 86400');    // cache for 1 day
        }</p>
  
  <pre><code>// Access-Control headers are received during OPTIONS requests
  if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
          header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
  
      if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
          header("Access-Control-Allow-Headers:        {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  
      exit(0);
  }
  $request=json_decode(file_get_contents("php://input"));
  $nom=mysql_real_escape_string($request-&gt;nom);
  $prenom=mysql_real_escape_string($request-&gt;prenom);
  $email=mysql_real_escape_string($request-&gt;email);
  $adresse=mysql_real_escape_string($request-&gt;adresse);
  $active=mysql_real_escape_string($request-&gt;active); 
  
  $con=mysql_connect("localhost","root","") or die(mysql_error());
  mysql_select_db("ionicbd",$con);
  
  $query="insert into user(`nom`,`prenom`,`email`,`adresse`) values($nom,$prenom,$email,$adresse)";
  $queryRes=mysql_query($query);
  if($queryRes) echo "1";
  else echo "2";
  </code></pre>
  </blockquote>
  
  <p>I got the response "Successfully Created Account" as output but I can't receive the data from the app </p>
  
  <p>The errors that I got :</p>
  
  <pre><code>Notice: Trying to get property of non-object in C:\xampp\htdocs\add.php on line 24
  
  Notice: Trying to get property of non-object in C:\xampp\htdocs\add.php on line 25
  
  Notice: Trying to get property of non-object in C:\xampp\htdocs\add.php on line 26
  
  Notice: Trying to get property of non-object in C:\xampp\htdocs\add.php on line 27
  </code></pre>