dou4624 2016-01-27 15:46
浏览 58

使用Angular / PHP将JSON对象插入MySQL表

So I have a JSON object I want to insert into a field in a MySQL table. When I do a "console.log(thatjson)", it prints the JSON object in the console with the text [Object], with all the information available when you click on the object. However, when I do a "alert(thatjson)" it prints "object Object" in the alert box, and when I check that table in phpMyAdmin, the field which is varchar(2000) only stored a string which says [object Object].

In my php, i have $property = json_decode($request->getBody()); to decode the angular passed json data, apparently that did not help. : (

Any ideas?

Edit:

Relevant Code:

$scope.update = function(thatjson){                
             $http.put('api/envisiondb/0', thatjson).success(function(data) {
                $scope.properties = data;
          });
        };

PHP Slim:

function editProperty($id) {
    $request = Slim::getInstance()->request();
    $property = json_decode($request->getBody());
    $sql = "UPDATE db SET username=:username..."

The JSON object is just a regular everyday JSON object

  • 写回答

1条回答 默认 最新

  • ds3422222 2016-01-27 17:06
    关注

    Make sure you pass your request data through the JSON.stringify() function.

    评论

报告相同问题?

悬赏问题

  • ¥15 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求