html - Ionic + Angular + PHP Undefined property: stdClass::$variable in insert.php -
there 3 files. when submit button clicked in ionic page, send inputs controller, , controller parse insert.php. forms input datas saved when use html(without ionic contents), form sends empty data mysql database, when use ionic. errors found firebugs are: 1. response - notice: undefined property: stdclass::$firstname in insert.php 2. post (json) - there no child objects please me, below 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 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 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 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 `tbl_order`(`firstname`,`lastname`,`email`,`telephone`) values('".$firstname."','".$lastname."','".$email."','".$telephone."')"; mysql_query($singam); // var_dump(mysql_fetch_assoc($singam));die; ?>
instead of using this,
$data = json_decode(file_get_contents("php://input"),true); var_dump($data);die; $firstname = $data->firstname;
try use $_post
like,
$firstname = $_post['firstname'];
Comments
Post a Comment