Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AngularJS可以';无法保存到数据库_Php_Angularjs - Fatal编程技术网

Php AngularJS可以';无法保存到数据库

Php AngularJS可以';无法保存到数据库,php,angularjs,Php,Angularjs,我最近才开始学习Angular,我仍然有一些困难 我似乎无法用角度数据更新数据库,但我可以从数据库中获取数据 这是我的代码,我想尝试和张贴我的数据 $scope.submit = function(infographic){ var data = { id: infographic.PK_InfoID, label: infographic.label, value: infographic.value

我最近才开始学习Angular,我仍然有一些困难

我似乎无法用角度数据更新数据库,但我可以从数据库中获取数据

这是我的代码,我想尝试和张贴我的数据

$scope.submit = function(infographic){
    var data = {
            id: infographic.PK_InfoID,
            label: infographic.label,
            value: infographic.value
        };
        console.log(data);
       $http.put("dataout.php", data).success(function(data) {
                                console.log(data);
                                                });
   };
下面是我使用的PHP:

if(isset($_POST['id'])){

    $id = $_POST['id'];
    $label = $_POST['label'];
    $value = $_POST['value'];
    $query = "UPDATE tblInfo SET label = '".$label"', value = '".$value"' WHERE PK_InfoID = '$id'";
    mysql_query($query);
}
有人能帮我吗

Thx调试您的PHP文件:

file_put_contents('/tmp/postContents.txt', print_r($_POST, true));
这将告诉您PHP脚本是否收到了预期的数据


另外:确保您没有创建SQL注入安全问题。您应该转义值($label等)。谷歌“sql注入php”获取信息。

Angular将以json编码字符串的形式发送请求数据。PHP将无法解析该字符串,因此
$\u POST
为空

使用类似于:

<?php
$data = json_decode(file_get_contents('php://input'), true);
if (json_last_error() === JSON_ERROR_NONE) {
  // use $data instead of $_POST
  print_r($data);
}

您自己试过调试吗?您是否检查过是否有数据发送到服务器(使用浏览器的web developer工具),是否看到任何javascript错误?是的,我知道SQL注入问题,但这没有问题,这不会生效。。。