使用Json数组将AngularJS http post发送到PHP程序

使用Json数组将AngularJS http post发送到PHP程序,php,angularjs,json,Php,Angularjs,Json,我正在使用AngularJS并尝试将参数发布到php程序中,以便php程序可以使用一个或多个变量进行选择 我需要传递一个json数组,它是我的sql绑定变量,下面是where_子句 这是Main.php <!DOCTYPE html> <html > <style> table, th , td { border: 1px solid grey; border-collapse: collapse; padding: 5px; } table tr:

我正在使用AngularJS并尝试将参数发布到php程序中,以便php程序可以使用一个或多个变量进行选择

我需要传递一个json数组,它是我的sql绑定变量,下面是where_子句

这是Main.php

<!DOCTYPE html>
<html >
<style>
table, th , td  {
border: 1px solid grey;
    border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
    background-color: #f1f1f1;
}
table tr:nth-child(even) {
    background-color: #ffffff;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="customersCtrl">

<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>

</div>

<script>
var app = angular.module('myApp', []);

app.controller('customersCtrl', function($scope, $http)
               {
               var req = {
               method: 'POST',url: 'angular_master.php',
               headers: {
               'Content-Type': undefined
               },
               params: { what_to_do: "angular_users6", where_clause: '[{"sqlvalue1":"searchvalue1","sqlvalue2":"searchvalue2"}]'}
               }

               $http(req).then(function (response) {$scope.names = response.data.records;});
               });

</script>

</body>
</html>
我在我捕获的日志中得到以下内容 日志:

问题是最后一个echo语句“where_array:”(此行上方的行不显示sqlvalue1和sqlvalue2的值,尽管print_R echo显示这些值


由于传递的where_子句可能包含多个值,为什么最后一个回送where_数组为空。

似乎您的foreach是错误的。where_数组的格式是:

其中_数组=[[“sqlvalue1”=>webcastpoa@thepentecostals.org,“sqlvalue2”=>na]]

尝试foreach($where_数组[0]作为$rows)

if ($what_to_do == "angular_users6")
    {
        $json = $where_clause;


        $where_array = json_decode($json,true);


        error_log("\n where_clause_json : " . print_R($json,TRUE) ,3,$filename_master);
        error_log("\n where_clause_array: " . print_R($where_array,TRUE) ,3,$filename_master);

        $sqlvalue1 = "";
        $sqlvalue2 = "";
        foreach($where_array as $rows)
        {
            $sqlvalue1 = mysqli_real_escape_string($conn, $rows['sqlvalue1']) ;
            $sqlvalue2 = mysqli_real_escape_string($conn, $rows['sqlvalue2']);

        }
        error_log("\n  where_array: " . $sqlvalue1 . " " . $sqlvalue2 ,3,$filename_master);
where_clause_json : [{"sqlvalue1":"searchvalue1","sqlvalue2":"searchvalue2"}]
 where_clause_array: Array
(
    [0] => Array
        (
            [sqlvalue1] => searchvalue1
            [sqlvalue2] => searchvalue2
        )

)

  where_array: