使用Angular/PHP将JSON对象插入MySQL表 [英] Inserting JSON object into MySQL table with Angular/PHP
问题描述
所以我有一个JSON对象,我想将其插入MySQL表的字段中.当我执行"console.log(thatjson)"时,它将在控制台中显示带有文本[Object]的JSON对象,并在单击该对象时提供所有信息.但是,当我执行"alert(thatjson)"操作时,它会在警报框中打印"object Object",而当我在phpMyAdmin中检查该表时,varchar(2000)字段仅存储了一个字符串,该字符串表示[object Object]
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].
在我的php中,我有$ property = json_decode($ request-> getBody());解码角度传递的json数据,显然没有帮助. :(
In my php, i have $property = json_decode($request->getBody()); to decode the angular passed json data, apparently that did not help. : (
有什么想法吗?
相关代码:
$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..."
JSON对象只是日常的常规JSON对象
The JSON object is just a regular everyday JSON object
推荐答案
请确保您通过JSON.stringify()
函数传递请求数据.
Make sure you pass your request data through the JSON.stringify()
function.
这篇关于使用Angular/PHP将JSON对象插入MySQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!