Problems inserting data to mysql - New to Ionic -?

Hello I am trying to isnert some data into a MYSQL table , it some what works, when i click submit it creates a new entry in the table but none of the information is being sent to the php file.

Here is what I have

var app = angular.module('starter', ['ionic']); ($ionicPlatform) {
    $ionicPlatform.ready(function () {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
        if (window.StatusBar) {

app.controller('customersCtrl', function ($scope, $http) {

	.success(function (response) { $scope.names = response.records; });

app.controller('newInvoice', function ($scope, $http) {

    $scope.addNewInvoice = function (add) {
    var data = {
    $"", { 'firstname': $scope.newInvoice.firstname, 'lastname': $scope.newInvoice.lastname })
        .success(function (data, status, headers, config) {



$mysql_host = "localhost";

$mysql_database = "DB";

$mysql_user = "user";

$mysql_password = "pass";

// Create connection

$conn = new mysqli($mysql_host, $mysql_user, $mysql_password,$mysql_database);

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);


	$data = json_decode(file_get_contents("php://input"));

$fstname = mysql_real_escape_string($data->firstname);

$lstname = mysql_real_escape_string($data->lastname);


$sql = "INSERT INTO invoices (customer_first,customer_last) VALUES ('$fstname','$lstname')";

$result = $conn->query($sql);





<!DOCTYPE html>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="css/" rel="stylesheet">
    <!-- ionic/angularjs js -->
    <script src="lib/ionic/js/ionic.bundle.js"></script>

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <script src="js/app.js"></script>
<body ng-app="starter">

        <ion-header-bar class="bar-stable">
            <h1 class="title">Test</h1>
            <div ng-controller="customersCtrl">

                    <li ng-repeat="x in names">
                        {{ x.Username }}
                        {{ x.Password }}

            <div ng-controller="newInvoice">
                <form name="addinvoice" method="post">
                    First Name:<input type="text" ng-model="newInvoice.firstname" name="firstname"/>
                    Last Name:<input type="text" ng-model="newInvoice.lastname" name="lastname"/>
                    <button data-ng-click="addNewInvoice()" name="add">Add Friend</button>


Test you with Rest Client like PostMan to ensure php saving data into database .

Then test from ionic.

Send data to query.php

Ok with using postman I was able to get information INTO my database. so once I knew my insert.php was working correctly with using postman. But I believe my solution to my error came when adding this header to my php file

header(‘Access-Control-Allow-Origin: *’);

I belive this is the CORS header, not postive but it worked for me.