简体   繁体   中英

Inserting JSON object into MySQL table with Angular/PHP

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

确保您通过JSON.stringify()函数传递请求数据。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM