0
有三個文件。當在離子頁面中點擊提交按鈕時,它將把所有輸入發送到控制器,然後控制器將解析到insert.php。當我僅使用html(不含離子內容)時,表單輸入數據將被保存,但當我使用IONIC時,表單將空數據發送到mysql數據庫。從firebugs發現的錯誤是: 1.響應 - 注意:未定義的屬性:stdClass :: $ firstname in insert.php 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>
頁 - 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;
?>
是否傾銷$數據顯示,預計結構? ANYWAY,您的查詢非常容易破壞,因此非常不安全,而不是由惡意黑客,只是由可憐的奧哈拉先生 –
var_dump($ data)的輸出是什麼;當var_dump,array(0)時是' – Archish
' {} –