有三个文件。当在离子页面中单击提交按钮时,它将所有输入发送到控制器,然后控制器将解析为insert.php。当我只使用html(没有离子内容)时,表单输入数据被保存,但是当我使用IONIC时,表单将空数据发送到mysql数据库。我从firebugs发现的错误是: 1.响应 - 注意:未定义的属性:insert.php中的stdClass :: $ firstname 2. POST(JSON) - 没有子对象 请帮帮我,下面是我的档案。
第01页 -
<ion-content>
<form>
<br><br>
<center>
<ion-list>
<!--Step 1 Billing Details-->
<div ng-repeat="group in groups">
<ion-item class="item-stable checkout item ng-binding active" ng-click="toggleGroup(group)" ng-class="{active: isGroupShown(group)}">
<i class="icon" ng-class="isGroupShown(group) ? 'ion-minus' : 'ion-plus'"></i>
{{group.name}}
</ion-item>
<ion-item class="item-accordion" ng-repeat="item in group.items" ng-show="isGroupShown(group)">
<input ng-required="true" ng-model="firstname" class="dumbie" type="text" placeholder="{{item.subName}}">
<span class="error" ng-show="myForm.first_name.$error.required">First name is required!</span>
<input ng-required="true" ng-model="lastname" class="dumbie" type="text" placeholder="{{item.subLName}}">
<div role="alert"> <span class="error" ng-show="myForm.last_name.$error.required"> Last name is required!</span> </div>
<input ng-required="true" ng-model="email" class="dumbie" type="text" placeholder=" {{item.subEmail}}">
<div role="alert"> <span class="error" ng-show="myForm.email.$error.required"> Email is required!</span> </div>
<input type="button" value="submit" ng-click="insertdata()"><br/>
</form>
</ion-content>
Page - 2 - 角度控制器
$scope.insertdata=function(){
var link = 'http://edu.local/fb_store/www/templates/insert.php';
$http.post(link,{'firstname':$scope.firstname,'lastname':$scope.lastname,'email':$scope.email,'telephone':$scope.telephone})
.success(function(data,status,headers,config){
console.log("Data inserted successfully");
});
}
第3页 - Insert.php
<?php
$data = json_decode(file_get_contents("php://input"),true);
var_dump($data);die;
$firstname = $data->firstname;
$lastname = $data->lastname;
$email = $data->email;
$telephone = $data->telephone;
mysql_connect("localhost","root","");
mysql_select_db("example_demo");
$singam = "INSERT INTO `tbl_order`(`firstname`,`lastname`,`email`,`telephone`)
VALUES('".$firstname."','".$lastname."','".$email."','".$telephone."')";
mysql_query($singam);
// var_dump(mysql_fetch_assoc($singam));die;
?>
答案 0 :(得分:0)
而不是使用它,
$data = json_decode(file_get_contents("php://input"),true);
var_dump($data);die;
$firstname = $data->firstname;
尝试使用$_POST
之类的内容,
$firstname = $_POST['firstname'];