Ionic app将表单数据发送到mysql

时间:2015-03-18 12:18:21

标签: php mysql angularjs cordova ionic-framework

我编写了一个代码,用于将带有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);
}

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

1 个答案:

答案 0 :(得分:0)

我想通过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