douwen1313 2017-01-12 13:42
浏览 25
已采纳

离子角度 - 注册问题

Controller for sign-up

.controller('signupCtrl', 

function($scope,$http,$ionicPopup,$state,$ionicHistory) {

    $scope.signup=function(data){
            var link = 'http://localhost/b_data/server/signup.php';
            $http.post(link, {n : data.name, un : data.username, ps : data.password , ph: data.phone , add : data.address , pin : data.pincode })
            .then(function (res){   
                $scope.response = res.data.result; 
                if($scope.response.created=="1"){   
                    $scope.title="Account Created!";
                    $scope.template="Your account has been successfully created!";

                    //no back option
                    $ionicHistory.nextViewOptions({
                        disableAnimate: true,
                        disableBack: true
                    });
                    $state.go('login', {}, {location: "replace", reload: true});

                }else if($scope.response.exists=="1"){
                    $scope.title="Email Already exists";
                    $scope.template="Please click forgot password if necessary";

                }else{
                    $scope.title="Failed";
                    $scope.template="Contact Our Technical Team";
                }

                var alertPopup = $ionicPopup.alert({
                        title: $scope.title,
                        template: $scope.template
                });


            });

    }
})

Backend signup.php few lines

if(isset($_GET["n"]) && isset($_GET["un"])&& isset($_GET["ps"])&& isset($_GET["ph"])&& isset($_GET["add"])&& isset($_GET["pin"]) )  {
    if( !empty($_GET["n"])  && !empty($_GET["un"])&& !empty($_GET["ps"])&& !empty($_GET["ph"])&& !empty($_GET["add"])&& !empty($_GET["pin"])  ){
 //rest of my db saving code
} }

As per debugging there is no issue i found in angular as well as php code, when debugging i found in php $_GET['n'] is not working so the rest of get codes.

Sort this out.

  • 写回答

1条回答 默认 最新

  • drqyxkzbs21968684 2017-01-12 13:47
    关注

    Why you're using $_GET in php. You should use $_POST in php since in angular you're using $http.post.

    JS

    var json = {n : data.name, un : data.username, ps : data.password , 
               ph: data.phone , add : data.address , pin : data.pincode };
    
    // Update wrap object with curly bracket
    $http.post(link, {data: json}).then(...);
    

    PHP

    // Added json decode
    $data = file_get_contents("php://input");
    $postData = json_decode($data);
    
    $n = $postData->n;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?