Ionic应用程序将表单数据发送到mysql


Ionic app send form data to mysql

我写了一段代码,用angularjs将离子应用程序的表单数据发送到mysql。我的代码运行良好,但只有空记录插入到mysql中这些是代码:

form.html

<div class="list"> 
<form>
<div><input type="text" ng-model="h" ></div>
<div><input type="text" ng-model="s"></div>
<button ng-click='SignUp();'>SignUp</button>
</form>
</div>

App.js

.controller('SearchCntrl', function($scope, $http) {
 $scope.SignUp = function() {
 $http.post('http://www.qatarperfectmedia.com/channel/postdata.php',
 {'h':$scope.h, 's':$scope.s}
 ).success(function(data, status, headers, config) {
    if (data.msg != '')
       {
         $scope.msgs.push(data.msg);
       }
    else
       {
         $scope.errors.push(data.error);
       }
      }).error(function(data, status) {
         $scope.errors.push(status);
       });
}
})

postdata.php

 $data = json_decode(file_get_contents("php://input"));
 $hospital = mysql_real_escape_string($data->h);
 $specialty = mysql_real_escape_string($data->h);
 $qry = 'INSERT INTO doctors (hospital,specialty) 
 values ("'.$hospital.'","'.$specialty.'")';
 $qry_res = mysql_query($qry);
 if ($qry_res) {
    $arr = array('msg' => "User Created Successfully!!!", 'error' => '');
    $jsn = json_encode($arr);
    print_r($jsn);
} else {
    $arr = array('msg' => "", 'error' => 'Error In inserting');
    $jsn = json_encode($arr);
    print_r($jsn);
}

我面临的问题是,当提交表单时,只有空记录被插入数据库。你的

我发现它通过url传递值,这非常适合

html页面

<div class="list"> 
  <form>
    <div><input type="text" ng-model="input.h" ></div>
    <div><input type="text" ng-model="input.s"></div>
    <button ng-click="SignUp(input);">SignUp</button>
  </form>
</div>

控制器

.controller('SearchCntrl', function($scope, $http) {
  $scope.SignUp= function (input){  
    // enter code here
    $http.post("http://www.casda.com/postdata.php?first="+input.h+"&second="+input.s).success(function(data) {
      $scope.tasks = data;
    });
  }
});

postdata.php

// get data from url
if(isset($_GET['first'])){
  $foo= $_GET['first'];
  $foo1= $_GET['second'];
}
// other query code