php - Ionic + Angular + PHP 未定义属性:insert.php 中的 stdClass::$variable

标签 php html mysql angularjs ionic-framework

一共有三个文件。当在 ionic 页面中单击提交按钮时,它会将所有输入发送到 Controller ,然后 Controller 将解析到 insert.php。当我只使用html(没有ionic内容)时,表单输入数据被保存,但当我使用IONIC时,表单将空数据发送到mysql数据库。我从 Firebug 中发现的错误是: 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>
                            &nbsp; 
                            {{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页- 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");
                        });
                    }

第 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;
 ?>

最佳答案

不要使用这个,

$data = json_decode(file_get_contents("php://input"),true);
var_dump($data);die;
$firstname = $data->firstname;

尝试使用$_POST类似的东西,

$firstname = $_POST['firstname'];

关于php - Ionic + Angular + PHP 未定义属性:insert.php 中的 stdClass::$variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39637046/

相关文章:

php - 检查是否确实需要包含的 javascript 文件

javascript - 如何在新的 Google Calendar v3 API 结果上使用 PHP 的 'json_decode'?

html - 如何在 Electron 浏览器上加载嵌入在 iFrame 中的 PDF 文件

javascript - 需要一种在 MSIE8 中强制重绘 <select> 的方法

与插入和限制一起使用时的 MySql group_concat 行为

javascript - 陷入永恒循环

php - 在二对多关系中使用两个表或使用三个表和一个数据透视表

jquery - Div 在页面上的错误位置,直到触发页面调整大小

PHP 循环不适用于使用 MySQL 变量的 CSV 输出

mysql - 需要帮助优化查询性能