Reputation: 93
There are three files. When the submit button is clicked in the ionic page, it will send all inputs to controller, and then controller will parse to insert.php. Forms input datas are saved when I use only html(without ionic contents), but the form sends empty data to the mysql database, when I use IONIC. The errors i found from firebugs are: 1. Response - Notice: Undefined property: stdClass::$firstname in insert.php 2. POST (JSON) - There are no child objects Please help me, below is my file.
Page 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 - Angular Controller
$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");
});
}
Page 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;
?>
Upvotes: 0
Views: 291
Reputation: 870
Instead of using this,
$data = json_decode(file_get_contents("php://input"),true);
var_dump($data);die;
$firstname = $data->firstname;
try to use $_POST
something like,
$firstname = $_POST['firstname'];
Upvotes: 0